Hi,
Please can you assist with the following? I've got a WinGrid that's bound to a DataTable with cols A and B. The cells of both columns are being updated regularly. My goal is, for each row, to format the background of col A based on the changing values in col B. It's an urgent requirement, so early assistance would be much appreciated.
Many thanks,
James
Thanks for your help, guys! That's exactly the solution I needed.
Best regards,James
Hi James,
After the merge completes, you can force the grid to refresh:
grid.Rows.Refresh(FireInitializeRow)
Hi Michael,
Ok thanks - nice to see that it can be made to work. It seems the reason the event isn't firing in our case is that we do updates via a mass Merge() on the source DataTable. This updates the grid's cell vals but doesn't trigger InitializeRow. An update to your sample code will show this:
table.PrimaryKey = new DataColumn[] { table.Columns[0] };
...
private void updateButton_Click(object sender, EventArgs e) { int a = Convert.ToInt32(textBox1.Text); int b = Convert.ToInt32(textBox2.Text); var mergetable = new DataTable("Cities"); mergetable.Columns.Add("CityID", typeof(int)); mergetable.Columns.Add("City", typeof(string)); mergetable.Columns.Add("Number", typeof(int)); mergetable.Rows.Add(new object[] { table.Rows[a]["CityID"], table.Rows[a]["City"], b }); if (a > ultraGrid1.Rows.Count) { return; } table.Merge(mergetable); table.AcceptChanges(); }
Aside from doing the merge manually, could you possibly suggest another workaround?
James,
The InitializeRow event will fire when you make a change to the underlying data source. I have attached a new version of the sample application that I attached earlier which demonstrates this. In this new version I have a ButtonClick event which will modify the DataTable using values that you can input into textboxes on the Form and you will see that the colors change immediately according to the values that you put in. Take a look at it and let me know what you think. You may also be able to do this with the "AfterCellUpdate" event, but I didn't get a chance to try that yet.
Thanks for your response. Sorry I should have explained - the grid is readonly with updates being done directly to the underlying data source. When a value changes, the cell text changes, but neither AfterCellUpdate nor InitializeRow get raised. I just need to hook into some 'cell text changed' event so I can apply the formatting.