Hi!
I am adding rows to datasourse of the grid and want to get newly added rows (to select or mark them). How to do this?
I am adding rows like this:
//copy old row to new row with a different name
DataRow newDataRow = newDataTable.NewRow(); foreach (DataColumn dataColumn in newDataTable.Columns) //init from input { newDataRow[dataColumn.ColumnName] = oldRow[dataColumn.ColumnName]; } newDataRow["Name"] = newName; newDataTable.Rows.Add(newDataRow);
ultraGrid1.Rows[newDataRow].Selected = true; //this is not compiling
Well, if you are adding a child row, then there's no easy way to find it in the grid unless you know the whole hierarchy. You would have to find the parent row that the row belongs to and then look at the last child of that parent.
If you want to do this by brute force, you could loop through all the rows in the grid recursively and find a row where the ListObject of the row matches the row you just added.
I have Hierarchical multiband grid. So ultraGrid1.Rows.Count always gives me number of rows in the top-level band. Though I can see that inserted row is always the last row in the band there it was inserted. I can't access band with the new row because I am inserting in the dataTable by name like this:
dataTable = this._HierarchicalDataSet.Tables["Type" + ultraGrid1.Selected.Rows[0].Cells["Level"].Value.ToString()]
DataRow newDataRow = dataTable.NewRow();
...//init row
dataTable.Rows.Add(newDataRow);
so I don't now the index of this band to access it.
The new row will always be added as the last row in the grid. So why not just do something like this:
ultraGrid1.Rows[ultraGrid1.Rows.Count-1].Selected = true;
My lastDataRow is of type DataRow, not UltraGridRow - so I can't compare it in RowInitialize. Also I need to select only one row in one place - not all the rows that can be added to my grid. I tried GetRowWithListIndex but also couldn't get anything from it because I have DataRow.
this.ultraGrid1.DisplayLayout.Bands[0].AddNew(); gives me an error if Bands[0] is not active and I donno how to make it active before adding row. Besides Bands[0] can be empty before adding row and in this case AddNew() again give me an errorof unknown context
My "this.lastDataRow" was just an implication that you could store the row yourself and then check it in InitializeRow. Did you try my other suggestion about using the GetRowWithListIndex?
You could also directly add it to the grid:
UltraGridRow newRow = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
If for whatever reason you can't use these approaches, you could loop through the rows in the grid until you found your row, but I'd prefer one of the two approaches listed here.
-Matt