Datagrid refresh + itemrenderer
Can anybody help me out with datagrid issue with itemrenderer?
I am using datagrind with signle column with itemrenderer to populate data from server in XML format.
It's work fine without itemrenderer , but for some reason it does not get refreshed properly with itemrenderer.
i already checked my xml several times it is correct, also working correctly without itemrenderer.
Thanks in advance,
waiting for any suggestions................
This type of problem can be very difficult to troubleshoot. I would suggest trying to narrow it down by boiling the code down to a simplified yet complete code that still exhibits the problem. Then if you have not solved the issue, post that simplified yet complete code here and an answer should come soon.
Similar Messages
-
Flex spark dataGrid gridColumn itemrenderer binding bug
I hava a TextInput within mx DataGrid gridColumn itemrenderer and binding its text to {data.f1} ,
when I set DataGrid dataProvider column (0,0) to "value1" by actionsript code,
it will update "value1" to TextInput field.
But if I change to spark DataGrid, TextInput Text won't be changed.
Please see below two samples, when user click "set var" button, it set dataProvider column (0,0) to "value1",
sample1 is in mx comopent, it works fine and will update "value1" to TextInput Text.
sample2 is in spark component, it did not work.
anyone can help for spark component ?
many thanks.
*** sample1 (mx componet): ***
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
layout="absolute">
<mx:Button x="235" y="52" label="set var" click="setVar()"/>
<mx:DataGrid id="grid_1" dataProvider="{ia_row}" x="25" y="52">
<mx:columns>
<mx:DataGridColumn dataField="f1" headerText="Column 1">
<mx:itemRenderer>
<fx:Component>
<mx:TextInput text="{data.f1}" width="95%"/>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="f2" headerText="Column 2"></mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var ia_row:ArrayCollection = new ArrayCollection([
{f1:"a1", f2:"b1"},
{f1:"a2", f2:"b2"}
private function setVar():void{
var t_row:Object = ia_row.getItemAt(0);
t_row.f1 = "value1";
ia_row.setItemAt(t_row, 0);
]]>
</fx:Script>
</mx:Application>
*** sample2 (spark componet): ***
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
>
<s:Button x="267" y="94" label="set var" click="setVar()"/>
<s:DataGrid id="grid_1" x="55" y="94" width="204" height="139" dataProvider="{ia_row}">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="f1" headerText="Column 1" width="120">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:TextInput text="{data.f1}" width="95%"/>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
<s:GridColumn dataField="f2" headerText="Column 2"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var ia_row:ArrayCollection = new ArrayCollection([
{f1:"a1", f2:"b1"},
{f1:"a2", f2:"b2"}
private function setVar():void{
var t_row:Object = ia_row.getItemAt(0);
t_row.f1 = "value1";
ia_row.setItemAt(t_row, 0);
]]>
</fx:Script>
</s:Application>sir, I think it does not send CHANGE event to dataGrid, so my suggestion is following:
private function setVar():void{
var t_row:Object = ia_row.getItemAt(0);
Alert.show(t_row.f1);
t_row.f1 = "value1";
ia_row.setItemAt(t_row, 0);
ia_row.refresh();//it is used to dispatch Event if dataprovider was changed. -
Flex datagrid custom itemRenderer - making column NOT EDITABLE
Hi all,
I am new to flex and having been trying to build custom editors and renderers for datagrid. I ran into this problem trying to fix another one (http://forums.adobe.com/post!reply.jspa?message=3569216)
The problem is :
I have a custom editor and a renderer for a text column. The whole grid is editable (i.e; editable=true). But clicking on the cell does not show me the editor. However, if I change the renderer to mx.controls.label, clicking on it takes me to my custom editor.
Can anyone please tell what I am doing wrong?? I am pasting the relevant code for more details.
DATAGRID : Replacing itemRenderer = "renderers.TextRenderer" with itemRenderer = "mx.controls.Label" makes the column editable
<mx:DataGrid id="dg" editable="true" rowHeight="100" width="861" x="10" y="10" height="498" dataProvider="{this.slideArray}">
<mx:columns>
<mx:DataGridColumn headerText="Text" width="100"
resizable="true" sortable="false"
itemRenderer = "renderers.TextRenderer"
itemEditor="editors.TextEditor"
dataField="text" editorDataField="myData"/>
</mx:columns>
</mx:DataGrid>
TEXT EDITOR
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true"
initialize="initEditor()">
<mx:TextInput id="edit" width="{this.width}" height="{this.height}"/>
<fx:Script>
<![CDATA[
import domain.Slide; // contains just one property :::: public var text : String
override public function set data(value:Object):void{
super.data = value;
this.edit.text = (value as Slide).text;
public var myData : String; // editor data field
import mx.binding.utils.BindingUtils;
private function initEditor():void{
BindingUtils.bindProperty(this,"myData", this.edit, "text");
]]>
</fx:Script>
</s:MXDataGridItemRenderer>
TEXT RENDERER
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<s:Label id="txt" horizontalCenter="0" verticalCenter="0"/>
<fx:Script>
<![CDATA[
import domain.Slide;
override public function set data(value:Object):void{
super.data = text;
this.txt.text = (value as Slide).text;
]]>
</fx:Script>
</s:MXDataGridItemRenderer>
Tricks I have tried and failed :
1. added the following code to the renderer
override public function get data():Object{
return super.data;
2. remove/change focusEnabled
3. wrote the same renderer in Actionscript - making it extend MXDataGridItemRenderer. I had to add the label component txt using addElement. Clicking on this does show th editor but it doesnt show the label txt at all... i.e; I dont get any text displayed.
I am using Flex 4.0 sdk.It worked!!!!!!! Thank you!! What you mentioned was indeed the problem!
Here is the custom item renderer's set data function
Before
Now
override public function set data(value : Object):void{
super.data = text;
this.txt.text = (value as Slide).text ; //txt is the Label control
override public function set data(value : Object):void{
super.data = value;
this.txt.text = (value as Slide).text ; //txt is the Label control
oh man, this is such a stupid mistake. I think I was confused with having three text properties - one inherited from MXDataGridItemRenderer, one in my txt Label control and one on my slide.
I had no idea that sending the value up to the super class was so important. None of the docs I read seemed to give much importance to this statement.
thanks so much and sorry for taking up so much of your time. I guess it is uncessary to post any more code. -
Datagrid refresh problem?
fileListArray.refresh();
dg_curtainmanager.invalidateList();
dg_curtainmanager.invalidateDisplayList();
<mx:DataGrid id="dg_curtainmanager" showHeaders="true" editable="true" includeInLayout="false" dataProvider="{fileListArray}" creationComplete="" variableRowHeight="true" wordWrap="true" rowCount="{fileListArray.length}" width="100%" >
<mx:DataGridColumn headerText="Parent Folder" sortable="true" editable="false" width="250" minWidth="65" wordWrap="true" >
<mx:itemRenderer>
<fx:Component>
<mx:HBox width="100%"
horizontalAlign="left" verticalAlign="middle">
<mx:Image source="@Embed(source='images/edit_16.gif')" toolTip="Select Starting Folder" buttonMode="true" click="outerDocument.parentfolderimagclick()" />
<mx:Label text="{data.document_folder_name}" color="black" />
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:DataGrid>@welcomecan,
What refresh problem you are facing.. in DataGrid? When you change your DataProvider for your grid the values are not being changed or somethingelse..??
Please always be clear in explaining your problem in order to get it resolved..
Thanks,
Bhasker -
Hi,
I have a datagrid using an itemRenderer that controls the input to be numbers.
From an external button, i am copying values from one column to multiple columns, the copy is done but it is not refreshing the values on the renderer.
It is a way to refresh that value?
Thanks
P.D:My renderer component is http://forums.adobe.com/message/3798449#3798449Here is my code:
public function ADG_itemEditEndHandler(event:AdvancedDataGridEvent):void {
// Check the reason for the event.
if (event.reason == AdvancedDataGridEventReason.CANCELLED)
// Do not update cell.
return;
event.itemRenderer['realValue'] = event.currentTarget.itemEditorInstance.text;
if (isNaN(event.currentTarget.itemEditorInstance.text) || event.currentTarget.itemEditorInstance.text == "" || Number(event.currentTarget.itemEditorInstance.text) < 0 ){
event.currentTarget.itemEditorInstance.text = 0;
event.itemRenderer['realValue'] = 0;
protected function disableEditing(event:AdvancedDataGridEvent):void {
if (event.columnIndex != 2){
if (event.rowIndex == 3 || event.rowIndex == 7 || event.rowIndex == 11 || event.rowIndex == 12 || event.rowIndex == 13 || event.rowIndex == 14 || event.rowIndex == 15 || event.rowIndex == 16 || event.rowIndex == 17){
event.preventDefault();
protected function copy_clickHandler(event:MouseEvent):void
// TODO Auto-generated method stub
if (myGrid.selectedItem == null){
Alert.show("Please select a row");
}else{
var numberOfColumns:Number = 4;
var first_year:Number = 2009
var rowIndex:Number = myGrid.selectedIndex;
var scrollIndex:Number = myGrid.verticalScrollPosition;
if (rowIndex == 3 || rowIndex == 11 || rowIndex == 12 || rowIndex == 13 || rowIndex == 14 || rowIndex == 15 || rowIndex == 16 || rowIndex == 17){
Alert.show("You cannot copy this item, it is a calculated row.");
}else{
for(var i:int=1; i < numberOfColumns; i++) {
var colName:String = (first_year + i).toString();
acData[rowIndex][first_year + i] = Number(acData[rowIndex][first_year]);
//acData.refresh();
acData.itemUpdated(myGrid.selectedItem);
myGrid.verticalScrollPosition = scrollIndex;
Alert.show("Data Copied."); -
DataGrid: Refresh one single row.
How do I refresh one single row in FlashBuilder DataGrid? I don't want to change the user's field sort order or selected row.
I would suggest that you create a backup of the datagrid
section of the code and then replace it with a datagrid where you
are displaying the datafileds and are not using any itemrenderer.
this way you will be able to identify if the itemrenderer is indeed
causing the problem.
Also, shouldn't you be binding the arraycolection in your
dataprovider. the data provider for my datagrid is usually bound
like
<mx:DataGrid id="DateGrid" width="100%" height="100%"
dataProvider="{shiftXLC}">
where shiftXLC is xmlListcollection or in your case it would
be the arraycollection.
hope this helps. -
How to set a checkbox in a datagrid's itemrenderer
Hello.
I've a spark datagrid. In a column there is a checkbox. In another column (I need to add it dynamically with actionscript) I've another checkbox (inside an itemrenderer). Cliccking on the first checkbox, I need to enable/disable the second checkbox.
More in general I need to interact not just with a checkbox but some other components inside columns added dynamically.
My question is: how to get (with actionscript) components inside an itemrender created dynamically?
Follow details related to the checkbox case:
Here my spark datagrid columns definitions:
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Azioni" resizable="false" sortable="false" width="49" ....../>
<s:GridColumn headerText="Iscritto" width="60" itemRenderer="renderers.EventoPersonaCheckBoxRenderer" dataField="iscritto"/>
<s:GridColumn id="personaEventoGridPersonaColumn" headerText="Persona" labelFunction...../>
<s:GridColumn id="personaEventoGridSocietaColumn" headerText="Societa" labelFunction..../>
</s:ArrayList>
</s:columns>
As you can see there si an itemrender. A checkbox is inside it.
I also need to add dynamically new colums to my datagrid. Each new column has an itemrender with a checkbox.
here the code to add a new columns:
private function createNewColumn():void
var newColumn:GridColumn = new GridColumn("column TEST");
newColumn.itemRenderer = new ClassFactory(NewColumnCheckBoxRenderer);
var cols:ArrayList = new ArrayList();
cols =eventoPersonaGrid.columns as ArrayList;
cols.addItem(newColumn);
The itemrenderer is the following:
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<fx:Script>
<![CDATA[
import events.CheckBoxEvent;
protected function eventoSubscribedCB_clickHandler(event:MouseEvent):void
data.iscritto = ! data.iscritto;
dispatchEvent(new CheckBoxEvent(CheckBoxEvent.UPDATE,data.iscritto));
]]>
</fx:Script>
<s:layout>
<s:HorizontalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<s:CheckBox id="eventoSubscribedCB" selected="{data.iscritto}" click="eventoSubscribedCB_clickHandler(event)"/>
</s:GridItemRenderer>
As explained above cliccking on the checkbox inside datagrid definition, I need to change the checkbox properties that is located inside an itemrenderer.
How can I do that?
Is there a way to get the itemrenderer and checkbox references by the selectedItem datagrid property?
thank you
PbesiThanks harUI.
Ok, I've to change how to face this kind of problems. Reading some articles I understood that there is not an itemrenderer for each row in a data grid. Instead, there are some itemrenderes (the number is the same of the visible rows in a datagrid) and they are applied on the other rows during the datagrid scroll. There no reason to try to get an itemrender instance. So the only way is to add these data inside a dataitem and get them with the "data" property. Ok, just is sounds strange for some properties to be carried on a valueobject because they aren't properties related to the data model (for example the infromation "checkbox is enabled/disabled"). Anyway it works. Thank you.
Pbesi -
DataGrid ComboBox itemRenderer/editor not updating dataProvider properly
I have a DataGrid with one column using a ComboBox as the itemRenderer. The column is editable but if you trace the dataProvider, the changes lag behind by one. So uncheck two row's ComboBox and the dataProvider only shows one row's data updated.
Any ideas?Yep, its a CheckBox, too early in the morning.
Another component (DataGrid) will be filtered depending on what rows in the ADG have their CheckBox checked, so leaving the row may be too late.
Here is the code I have so far. In the itemEditEnd event handler I'm trying to set the field in the dataProvider manually, but it causes an infinite loop. preventDefault and stopImmediatePropagation don't help.
----- CheckBoxRenderer.mxml -----
<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.CheckBox;
[Bindable] public var newSelected:Boolean;
]]>
</mx:Script>
<mx:CheckBox id="selectedChbx" selected="{data.FLAG}"/>
</mx:VBox>
----- mainapp.mxml -----
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.events.AdvancedDataGridEvent;
import mx.collections.ArrayCollection;
import mx.controls.CheckBox;
[Bindable] private var transactions:ArrayCollection = new ArrayCollection([
{orderID: "33725", theirOrderNumber: "10170", name: "Bob Smith", SKUs: "21", PICKS: "50", FLAG: "true"},
{orderID: "33729", theirOrderNumber: "10172", name: "Mary Wilson", SKUs: "3", PICKS: "6", FLAG: "true"},
{orderID: "33730", theirOrderNumber: "10176", name: "Fred Carson", SKUs: "1", PICKS: "2", FLAG: "true"},
{orderID: "33731", theirOrderNumber: "10177", name: "Morten Hills", SKUs: "5", PICKS: "16", FLAG: "true"},
{orderID: "33732", theirOrderNumber: "10178", name: "Bill Trundy", SKUs: "5", PICKS: "34", FLAG: "true"},
{orderID: "33734", theirOrderNumber: "10179", name: "Ocean Boat Supply", SKUs: "8", PICKS: "19", FLAG: "true"},
{orderID: "33736", theirOrderNumber: "10180", name: "Janet Aberdine", SKUs: "5", PICKS: "18", FLAG: "true"},
{orderID: "33737", theirOrderNumber: "10181", name: "Kim Restine", SKUs: "2", PICKS: "6", FLAG: "true"},
{orderID: "33738", theirOrderNumber: "10182", name: "Thomas Overby", SKUs: "5", PICKS: "12", FLAG: "true"}
public function handleGridChanged(evt:AdvancedDataGridEvent):void{
var newData:Boolean = CheckBoxRenderer(evt.currentTarget.itemEditorInstance).newSelected;
trace(evt.rowIndex);
var obj:Object = transactions.getItemAt(evt.rowIndex);
trace("BEFORE: " + obj.FLAG);
obj.FLAG = newData;
trace("AFTER: " + obj.FLAG);
transactions.setItemAt(obj, evt.rowIndex);
return;
evt.preventDefault();
evt.stopImmediatePropagation();
// for each(var item:Object in transactions){
//trace(item.FLAG);
]]>
</mx:Script>
<mx:Label fontSize="12" text="Bulk Print / Pull - Step 1"/>
<mx:HBox>
<mx:AdvancedDataGrid id="dgTransactions" dataProvider="{transactions}"
fontSize="12" editable="true" sortableColumns="true" height="500"
width="100%" itemEditEnd="handleGridChanged(event);">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="orderID" headerText="WMSOID" width="100"
editable="false" textAlign="center"/>
<mx:AdvancedDataGridColumn dataField="theirOrderNumber" headerText="Order #"
textAlign="center" width="130" editable="false"/>
<mx:AdvancedDataGridColumn dataField="name" headerText="Customer"
width="125" textAlign="left" editable="false"/>
<mx:AdvancedDataGridColumn dataField="SKUs" headerText="SKU's"
width="75" textAlign="right" editable="false"/>
<mx:AdvancedDataGridColumn dataField="PICKS" headerText="Picks"
width="75" textAlign="right" editable="false"/>
<mx:AdvancedDataGridColumn dataField="FLAG" headerText="I" width="20" textAlign="center"
editable="true" rendererIsEditor="true" editorDataField="newSelected"
itemRenderer="CheckBoxRenderer"/>
</mx:columns>
</mx:AdvancedDataGrid>
<mx:DataGrid>
</mx:DataGrid>
</mx:HBox>
</mx:Application> -
Hi All,
First let me explain my problem clearly.I am facing the
problem with refreshing datagrid for add,update,delete operations.
For adding task(todo app) i am using another mxml
component(PopUpwindow).when i do add,delete or update, changes are
happening
in database pakka and fine.There is no error in that.Only
problem is when i add or delete or update a task, datagrid has to
get refresh with the updated or new data.Then only from ui
user will know that he added a task or deleted a task etc right.
sometimes it's refreshing fine and sometimes not.If it
doesn't refresh at all times i can think of my logic.But if it's
happening sometimes and sometimes not.
after add or delete or update am using below 5 lines of code
to refresh datagrid.
getList.send(); //sending request again to load new data
using httpservice.
datagrid.dataProvider = resultList; //resultList is
bindabale ArrayCollection variable.
resultList.refresh(); //this line not all giving any
changes.i think it's not working
datagrid.validateDisplayList();
datagrid.validateNow();
Thnaks & Regards,
premadas.Hey harsha,
the following code i'm using for deleting a task.
<mx:HTTPService id="getTodo" url="
http://dev.edinc.in:8080/poc/ToDo/GetToDo.jsp"
result="resultHandler(event)"/>
private function delTask():void
delTodo.cancel();
delTodo.send(delData);
getTodo.send();
deltaskname.text = "";
deltaskdate.selectedDate = new Date();
deltaskcategory.selectedIndex = -1;
deltaskpriority.selectedIndex = -1;
deltaskstatus.selectedIndex = -1;
Anything i need to apply here.
Thanks & Regards,
Premdas. -
Datagrid: Custom Itemrenderer
Hello,
my Datagrid consists of a variable number of columns that are
handled by the same Itemrenderer. Now I have the problem that I
can't find out which column I belong to when I am in the override
set data function.
Any hints how i can back track to what column the "current"
Itemrenderer belongs or is processing at that moment?
Thanks and GzG
NerunI had the exact requirement. Multiple columns using the same
item renderer and needing to know what was clicked. Essentially I
solved it in three steps.
1. Override the datagid to add your own custom events;
package com.psc.eis.view
import mx.controls.DataGrid;
import mx.events.ListEvent;
[Event( name = "MyViewCurrentEvent", type =
"mx.events.ListEvent" ) ]
[Event( name = "MyEditCurrentEvent", type =
"mx.events.ListEvent" ) ]
[Event( name = "MyDeleteCurrentEvent", type =
"mx.events.ListEvent" ) ]
[Event( name = "MySearchEvent", type = "mx.events.ListEvent"
public class MyDataGrid extends DataGrid
public function MyDataGrid() { super()}
public static var
MY_VIEW_CURRENT_EVENT:String="MyViewCurrentEvent";
public static var
MY_EDIT_CURRENT_EVENT:String="MyEditCurrentEvent";
public static var
MY_DELETE_CURRENT_EVENT:String="MyDeleteCurrentEvent";
public static var MY_SEARCH_EVENT : String =
"MySearchEvent";
2. In your item renderer create a click handler that
dispatches the appropriate event
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="
http://www.adobe.com/2006/mxml"
horizontalAlign="center">
<mx:Script>
<![CDATA[
private function clickHandler() : void
import mx.events.ListEvent;
var event:ListEvent = new ListEvent(
MyDataGrid.MY_EDIT_CURRENT_EVENT );
event.itemRenderer = this;
owner.dispatchEvent(event);
]]>
</mx:Script>
<mx:Image id="imageDelete" source="images/bluepencil.gif"
width="20" click="clickHandler()"/>
</mx:HBox>
3. In your mxml for the datagrid setup the event handler
<psc:MyDataGrid id="dataGridProjects" dataProvider="{. .
MyViewCurrentEvent="viewCurrentHandler(event)"
MyEditCurrentEvent="editCurrentHandler(event)"
MyDeleteCurrentEvent="deleteCurrentHandler(event)"
>
That's it. -
DataGrid: custom ItemRenderer changes Header renderer
If I assign custom ItemRenderer to a DataGrid, this also affects headers, i.e. headers start looking as the fields in a grid. Not only that, but it seems that render is much worse and it really looks bad. Is this how it's supposed to be, is there a workaround to keep the headers as they should be and just change the actual renderers in the grid?
Post a bit of your code.
Sincerely,
Michael
Sent from my iPhone
El 16/07/2009, a las 23:24, mraak <[email protected]> escribió:
>
If I assign custom ItemRenderer to a DataGrid, this also affects
headers, i.e. headers start looking as the fields in a grid. Not
only that, but it seems that render is much worse and it really
looks bad. Is this how it's supposed to be, is there a workaround to
keep the headers as they should be and just change the actual
renderers in the grid?
> -
Is there a way that I can refresh the items in my DataGrid?. I am using C#. Some says that DataGrid.Items.Refresh() is the solution, but it doesn't work. Here's a snippet of my code.
namespace WpfApplication1
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
MongoClient mongoClient { get; set; }
MongoServer server { get; set; }
MongoDatabase database { get; set; }
MongoCollection<facultyData> collection { get; set; }
public MainWindow()
InitializeComponent();
loginDialog dlg = new loginDialog();
dlg.ShowDialog();
var dateTime = DateTime.Now;
dateTime_label.Content = dateTime;
public void Window_Loaded(object sender, RoutedEventArgs e)
MongoClient mongoClient = new MongoClient();
MongoServer server = mongoClient.GetServer();
MongoDatabase database = server.GetDatabase("facultyDataAndSchedule");
MongoCollection<facultyData> collection = database.GetCollection<facultyData>("faculty");
var results = collection.FindAll();
List<facultyData> resultList = results.ToList<facultyData>();
// Bind result data to WPF view.
if (resultList.Count() > 0)
Binding bind = new Binding(); //create a new binding to be used on the wpf
facultyDataGrid.DataContext = resultList; //sets the data binding for the control
facultyDataGrid.SetBinding(DataGrid.ItemsSourceProperty, bind); //syncs the data
facultyID_Textbox.DataContext = resultList;
facultyID_Textbox.SetBinding(DataGrid.ItemsSourceProperty, bind);
lastName_TextBox.DataContext = resultList;
lastName_TextBox.SetBinding(DataGrid.ItemsSourceProperty, bind);
private void viewMenu_click(object sender, RoutedEventArgs e)
MessageBox.Show("Hello", "hiThere");
private void fRViewMenu_click(object sender, RoutedEventArgs e)
documentViewer docViewer = new documentViewer();
docViewer.ShowDialog();
private void selectionChanged(object sender, SelectionChangedEventArgs e)
facultyData row = (facultyData)facultyDataGrid.SelectedItem;
facultyID_Textbox.Text = row.facultyID;
lastName_TextBox.Text = row.lastName;
firstName_TextBox.Text = row.firstName;
middleName_TextBox.Text = row.middleName;
age_TextBox.Text = row.age.ToString();
public void addData_Click(object sender, RoutedEventArgs e)
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase("facultyDataAndSchedule");
var collection = database.GetCollection<facultyData>("faculty");
var entity = new facultyData { facultyID = facultyID_Textbox.Text.ToString(),
age= Int32.Parse(age_TextBox.Text),
firstName= firstName_TextBox.Text.ToString(),
lastName = lastName_TextBox.Text.ToString(),
middleName = middleName_TextBox.Text.ToString(),
dateOfBirth="11/11/2011",
program= "progra", rank="gegs", services="gegsg", status="geh", yearsOfTeachingO=1, yearsOfTeachingS=1};
collection.Insert(entity);
private void refreshButton_Click(object sender, RoutedEventArgs e)
class facultyData
public ObjectId _id { get; set; }
public string facultyID { get; set; }
public string acadYear { get; set; }
public string program { get; set; }
public string lastName { get; set; }
public string firstName { get; set; }
public string middleName { get; set; }
public string dateOfBirth { get; set; }If you reset the ItemsSource collection and want to update the DataGrid you could use the BindingOperations.GetBindingExpression method and the UpdateTarget() method like this:
var be = BindingOperations.GetBindingExpression(facultyDataGrid, DataGrid.ItemsSourceProperty);
be.UpdateTarget();
If you want to refresh the value of a single property of a facultyData object in the DataGrid, the facultyData class should implement the INotifyPropertyChanged interface and raise its PropertyChanged event:
https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
class facultyData : INotifyPropertyChanged
private string _lastname;
public string lastName {
get {
return _lastname;
set {
_lastname = value;
NotifyPropertyChanged("lastName");
//the same for rest of the properties...
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
Then you can simply set the value of the property dynamically:
facultyData row = (facultyData)facultyDataGrid.SelectedItem;
row.lastName = "new Value!";
Hope that helps.
Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread. -
Flex 4 Advanced DataGrid Refresh with database record changes at server end
I've visited a number of posts regarding this problem and none of the solutions presented seem to fix the issue I'm having. I'm beginning to think it is a bug with the DataManagement functions in Flex.
In my application I have followed the example presented on the Flex 4 tutorials:
"Using data management to synchronize server updates".
http://help.adobe.com/en_US/Flex/4.0/FlexTutorials/WSbde04e3d3e6474c4292a0331216558354b-80 00.html#WSbde04e3d3e6474c4-211e6e7c12846356a0c-8000
I've tried with both client-side and server-side typing with the same issue.
I'm using Flex 4 with ColdFusion 9 connecting to an MSSQL 2008 database. The table I'm working with uses a GUID as the identifyer (I have also tried with unique numeric types too).
The application is running fine besides one issue. I am using the myService.commit(); control to do a bulk update to rows that have been added to the DataGrid. At the database end I am inserting values into some fields that are not determined at the client end. The database is updating fine, so the commit seems to be doing that part of the work. However, there does not seem to be any way of reflecting those new values provided at the ColdFusion CFC insert within the DataGrid. I've tried re-assigning the DataGrid to the dataProvider / different dataProvider after the commit. Refreshing the DataGrid using myDataGrid.dataProvider.refresh() seems to partly work. i.e. The Grid is refreshed with the records it held before I added any + the first row of the new inserts. The missing rows are only visible if I do not refresh at all (without their server side changes) or if I reload the entire page.
Any help would be greatly appreciated.
Cheers
Pat
PS. If I add further rows to the DataGrid and then commit a subsequent time then it refreshes with the rows that were missing on the previous commit and the first row of the latest commit.
Message was edited by: Pat MoodyMy solution when adding new values at the server end is to modify the createEmployee in the CFC to something like this. In this example I'm using modified_date as the additional field maintained at the server end. This could be any number of additional fields.
Basically it's doing an insert and then a select. Tried returning as array / Employee but couldn't get that to work so using the query object return type of "any". Using this method, no refresh is required on the DataGrid.
<cffunction name="createEmployee" output="false" access="remote" returntype="any" >
<cfargument name="item" type="Employee" required="true" />
<cfquery name="qCreateEmplyee" datasource="fb_tutorial_db" result="result">
INSERT INTO employees (first_name, last_name, gender, birth_date, hire_date, modified_date )
VALUES (<CFQUERYPARAM cfsqltype="CF_SQL_VARCHAR" VALUE="#item.fname#">,
<CFQUERYPARAM cfsqltype="CF_SQL_VARCHAR" VALUE="#item.lname#">,
<CFQUERYPARAM cfsqltype="CF_SQL_VARCHAR" VALUE="#item.gender#">,
<CFQUERYPARAM cfsqltype="CF_SQL_DATE" VALUE="#item.bdate#">,
<CFQUERYPARAM cfsqltype="CF_SQL_DATE" VALUE="#item.hdate#">,
<CFQUERYPARAM cfsqltype="CF_SQL_TIMESTAMP" VALUE="#now()#">)
</cfquery>
<cfset var qItem="">
<cfquery name="qItem" datasource="fb_tutorial_db">
SELECT
#result.GENERATED_KEY# as emp_id
,first_name as fname
,last_name as lname
,gender
,birth_date as bdate
,hire_date as hdate
,modified_date as mdate
FROM employees
WHERE emp_no = <CFQUERYPARAM CFSQLTYPE="CF_SQL_INTEGER" VALUE="#result.GENERATED_KEY#">
</cfquery>
<cfreturn qItem>
</cffunction> -
DataGrid CheckBox ItemRenderer
Hi
I am having some problems with my CheckBox extended
ItemRenderer for a DataGrid.
All works fine except now rollover does not work properly on
the DataGrid - you hover over a row and the first one you come to
highlights but thereafter it will not update to show other rows you
go over.
I am attaching the code to see if anyone can spot anything.
I've been searching the Internet for a solution for the last
day and a half but hopefully someone here can help me out !
Thanks in advance
ChrisNo, the itemRenderer should be wrapped into a container, so
"this" will refer to container itself.
this->ComboBox_id will be right way.
Here is the example of IR:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
width="100%"
verticalScrollPolicy="off" horizontalScrollPolicy="off">
<mx:Label
id="cellLabel"
x="0" y="0"
width="100%"
textAlign="right"
text="{data.hasOwnProperty('m_nDiscountPercent')?frmt_Percent.format(data.m_nDiscountPerc ent)
+ '%':'---'}"
paddingRight="10"/>
</mx:VBox>
Yours will look similar, just ComboBox instead of a Label.
Cheers,
Dmitri. -
Is there any way to refresh the datagrid control at runtime.
Hi,
when u want to refresh the datagrid component u just refresh the dataprovider.
example
suppose u use arraycollection as a dataprovider to datagrid. make it bindable.
when u want to refresh the component u refresh the dataProvider.
[Bindable]
var myData:ArrayCollection = new ArrayCollection()
//when u refresh
myData.refresh();
i think this will help u.
Thanks
Niranjan
Maybe you are looking for
-
Oracle Apps Standard Database Views not appearing in OBIEE
Hi I am trying to select the Standard database views of oracle apps. for example PO_HEADERS_V, PO_LINES_V.....etc. I am unable to see in the (import metadata ) page. I have selected the options (Tables, Keys, forign key, View) Thanks Ahmed
-
just updated my camera from Olympus E3 to the Olympus OMD EM5, I have downloaded all updates available, and the download for the plugin 6.7 was succesful, but the installation gives me a failed message. Can I do the new raw plugin in CS4, or do i ha
-
I recently switched from Rogers to iPhone with other carrier....now I find a feature that is lost....u can't save draft text messages on an iphone!! Interesting..Apple can build a thinner phone like iphone 5, but can't fix a simple glitch to allow us
-
Deploy shared variable on specific ip
Hi, there is the problem to deploy shared variable on a specific network interface. There are many network interfaces in my computer. If I wan to deploy the variable on the nework interface with the physical address 00:50:56:C0:00:01 and the ip 192.1
-
i have an iPhone and tried to sync with my iTunes on a Dell laptop for the first time. iTunes told me that i had to upgrade version of iTunes in order to sync. when i tried to update, it told me that i had to restore my iPhone. after restoring and up