Home Forums WinForms controls Xceed Grid for WinForms Using CellValueChanged in a bound grid Reply To: Using CellValueChanged in a bound grid

User (Old forums)
Member
Post count: 23064

ATM I managed to implement it by using the DataRow CellValueChanged event. Unfortunately it is triggered every time any of the cell values change:

// in the constructor:
this.gridControl1.AddingDataRow += new AddingDataRowEventHandler(gridControl1_AddingDataRow);
this.gridControl1.DataSource = am.getGrid().getDataSet().Tables[“Futures”];

void gridControl1_AddingDataRow(object sender, AddingDataRowEventArgs e)
{
Debug.WriteLine(“void gridControl1_AddingDataRow(object sender, AddingDataRowEventArgs e)”);
e.DataRow.CellValueChanged += new EventHandler(DataRow_CellValueChanged);
}

void DataRow_CellValueChanged(object sender, EventArgs e)
{
Xceed.Grid.DataRow r = sender as Xceed.Grid.DataRow;
if (r.Cells[“state”].Value.ToString().Replace(” “, “”) != “watched”)
r.BackColor = Color.LightGoldenrodYellow;
else
r.BackColor = Color.White;
}

Because of frequent changes of cell values which are not in the “state” column the event is raised unnecessarily often. I would prefer to hook my handler to the cell’s ValueChanged event like this:

void gridControl1_AddingDataRow(object sender, AddingDataRowEventArgs e)
{
e.DataRow.Cells[“state”].ValueChanged += new EventHandler(FuturesView_ValueChanged);
}

void FuturesView_ValueChanged(object sender, EventArgs e)
{
Debug.WriteLine(“Cell Value changed!! ” + sender.ToString());
Xceed.Grid.DataCell c = sender as DataCell;
Xceed.Grid.DataRow r = c.ParentRow as Xceed.Grid.DataRow;

if(c.Value .ToString().Replace(” “, “”) != “watched”)
r.BackColor = Color.LightGoldenrodYellow;
else
r.BackColor = Color.White;
}

Unfortunately this does not have any effect at all. Any suggestions?

Imported from legacy forums. Posted by twi (had 459 views)