We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Binding an IList in a GGC and update grid when item props change

Hi all,

I have a question about binding an IList to a ggc. Suppose the CustomItem class has a single property called CValue.

In the ui I have a textbox which sets the CValue property of every item in the IList (which is bound to the grid). Is there any way to get teh grid to automatically refresh/update when some CustomItems change?

Thanks,
Jack



4 Replies

AD Administrator Syncfusion Team May 28, 2008 11:53 AM UTC

For an arbitrary IList<>, there is no way for the grid to automatically refresh itself when a value is changed outside of the grid. If you were using an IBindingList<>, then yes the grid could automatically reflect the changes made outside the grid as long as the IBindingList.ListChanged event is raised properly.

In the situation you described of having external TextBoxes changing the grid values, then you could subscribe to the textBox.Validated event and force the grid to update at that point.

void textBox1_Validated(object sender, EventArgs e)
{
//update the value in the list somehow...
list[row].CValue = textBox1.Text;
row = (++row) % list.Count;

//force the grid to refresh itself.
gridGroupingControl1.Table.TableDirty = true;//.Reload();
gridGroupingControl1.Update();

}





TE test May 28, 2008 01:44 PM UTC

the problem then is that the grid loses its state. if the user has collapsed some groups and expanded others there is no way to maintain the current state. Is there any way around this?

thx



AD Administrator Syncfusion Team May 28, 2008 02:31 PM UTC

For an arbitrary IList, there is no way to have this update happen magically as it would if you were using an IBindingList. I think you will either have to redo the whole grid when the change happens (as suggested above) or you will have to somehow find the grid record that changed, and explicitly trigger the change in that record. The only way I would know to do this for an arbitary IList is brute force. Here is a little code snippet that modifies the sample above showing this working from the textbox (also remove the timer in the sample.)


void textBox1_Validated(object sender, EventArgs e)
{
//update the value in the list somehow...
list[row].CValue = textBox1.Text;


//force the grid to refresh itself.
// gridGroupingControl1.Table.TableDirty = true;//.Reload();
// gridGroupingControl1.Update();

for (int i = 0; i < gridGroupingControl1.Table.FilteredRecords.Count; ++i)
{
if (gridGroupingControl1.Table.FilteredRecords[i].GetData().Equals(list[row]))
{
gridGroupingControl1.Table.FilteredRecords[i].SetValue("CValue", list[row].CValue);
break;
}
}

row = (++row) % list.Count;
}





AD Administrator Syncfusion Team May 28, 2008 02:45 PM UTC

If you really do know the position in the IList that was modified (as in the sample - we know the item whose index is 'row' in IList is being modified), then instead of looping through the FilteredRecords collection trying to find the item, you can use the UnsortedRecords collection and just set the value.

void textBox1_Validated(object sender, EventArgs e)
{
//update the value in the list somehow...
list[row].CValue = textBox1.Text;

//change the record pointed to by row
gridGroupingControl1.Table.UnsortedRecords[row].SetValue("CValue", list[row].CValue);

//increment row to hit another value next time
row = (++row) % list.Count;
}




Loader.
Live Chat Icon For mobile
Up arrow icon