Dear all,
I have the checkbox in the row in the ultragrid. If checkbox is checked or unchecked, I will modify the current row data, How to do ?? Any sample code?? In what ultragrid event . e.g.
if(Row[i].Cells[0] == true)
{
Row[i].Cells[9].Value=......
}
else
Hi,
If you want your update to occur immediately when the user clicks on the checkbox, then you should use the CellChange event of the grid.
Note that you cannot use the Value of the cell inside this event - you must use the Text property of the cell, because Value does not get updated until the user leaves the cell and the change is committed.
How can I access the Checked value in the checkbox of the first column in the ultragrid of cellChange event??
I have solved by writing below code:
bool.parse(this.ultragrid1.activecell.text)==true
That's the correct way to do it.
You cannot use the Value property of the cell inside the CellChange event, because this event fires on every keystroke or every change to the cell while it is still in edit mode. The Value property reads from the underlying DataSource of the grid, which does not get updated until you leave the cell.
So using the Text property is the right way to go.
Thanks! this was a VERY enlightening and useful explanation...
Hi , I have a similar checkbox column in my ultragrid . But only in the first column. The other columns are String types. NOTE : I am adding the boolean column in a Datatable and binding it to my ultragrid .
I have made CellChange event method on the grid. Now , i want it to do something only if the first columns content changes i.e only the boolean column. CellChange however latches onto any cell change. Is there anyway I could check the column name or header in the cellChange method ?
or even if i can check it the cell belongs to column[0] i.e first column , that will do ?
Thanks ,
Prasaanth
The event gives you the cell, so you can get the column and use the key to determine if it's the one you want.
void ultraGrid1_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.Key == "Boolean 1") { } }
Possible solution would be to set the cell value from the cell change event which would fire the AfterCellUpdate event (I expected AfterCellUpdate to fire having checked a Band[0] column checkbox)... I needed to check "MyColumn" on the child rows having checked the "MyColumn" on the parent row (renamed variables and grid to some generic names incase of typo's but you get the idea):
private bool _updatingCell = false;
private void MyGrid_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.Key == "MyColumn") { e.Cell.Value = Convert.ToBoolean(this.MyGrid.ActiveCell.Text); } }
private void MyGrid_AfterCellUpdate(object sender, CellEventArgs e) { if (!this._updatingCell) { // if band 0 then mark all child rows if (e.Cell.Row.Band.Index == 0) { // changed to true if (e.Cell.Value != null && (bool)e.Cell.Value) { IEnumerator enumerator = e.Cell.Row.ChildBands[0].Rows.GetEnumerator(); this._updatingCell = true; while (enumerator.MoveNext()) { UltraGridRow row = enumerator.Current as UltraGridRow; if (row != null) { row.Cells["MyColumn"].Value = true; } } this._updatingCell = false; enumerator = null; } // changed to false if (e.Cell.Value != null && !(bool)e.Cell.Value) { IEnumerator enumerator = e.Cell.Row.ChildBands[0].Rows.GetEnumerator(); this._updatingCell = true; while (enumerator.MoveNext()) { UltraGridRow row = enumerator.Current as UltraGridRow; if (row != null) { row.Cells["MyColumn"].Value = false; } } this._updatingCell = false; enumerator = null; } } } }
The Key of the column is the name of the field in the data source. By default, it's what you see in the column header (although you could change this via the column.Header.Caption).
Using the index, like you are doing, it generally not a good practice, because the index can be easily changed. For example, the user can move the column in the grid by default, and if they change the column position, the index will change.
The Key will never change (unless you change the name of the field in your data source).
if (e.Cell.Column == stepsUltraGrid.DisplayLayout.Bands[0].Columns[0])
This is what I did finally . I didn't know where I could set the Key for the dataTable. Since I was not sure where I can set the Key property as I am creating a DataTable and putting it in my ultragrid instead of setting up the ultragrid columns dircetly.