Hello,
Is there way to obtain a UltraGridRow from a DataRow? Please advise.
Adrian
vrn said:Question 1: In my case, the grid is bound to the DataView defined on a DataTable. At any point of time, one may see a subset of all records on the grid depending on the filter clause on the DataView. If the GridRow is not visible at the time of doing the GetRowWithListIndex, what would it return me? In other words, does the GetRowWithListIndex work only if the GridRow is visible to the user?
Question 1: In my case, the grid is bound to the DataView defined on a DataTable. At any point of time, one may see a subset of all records on the grid depending on the filter clause on the DataView. If the GridRow is not visible at the time of doing the GetRowWithListIndex, what would it return me?
In other words, does the GetRowWithListIndex work only if the GridRow is visible to the user?
I'm not sure the visibility of the grid would make any difference. Do you have some reason to think that it does? It's possible that the method will fail to find the row if the rows have not been created, yet. And that might be the case if the grid has never painted. But I would think calling GetRowWithListIndex would force the creation of the rows at that point, just as accessing the indexer would do.
vrn said:Question 2:In response to a previous email from Adrian where he used this construct UltraGridRow gridRow = UltraGrid1.DisplayLayout.Rows.GetRowWithListIndex(table.Rows.IndexOf(DataRow)); you wrote Mike Saltzman"] That's good. But it's a bit inefficient, because you are now doing two linear walks instead of one. Once walk through the data rows with the call to IndexOf, and a second one through the grid's Rows collection for GetRowWithListIndex. I see why this is not as efficient as your original suggestion. But when I tried to do it differently but I could not find any way to go from the DataRow to its index. I thought there would be a Index property on the DataRow that I could use. Any suggestions?You probably have to do it this way if you are using a filtered DataView so that you get the correct index of the DataRow. The alternative would be to walk through the grid rows and compare the grid row's ListObject with the DataRow you are looking for. This would be more code and might look like it's doing more work, but it's actually less, since it's only walking over the rows once.
Question 2:In response to a previous email from Adrian where he used this construct
UltraGridRow gridRow = UltraGrid1.DisplayLayout.Rows.GetRowWithListIndex(table.Rows.IndexOf(DataRow));
you wrote
Mike Saltzman"] That's good. But it's a bit inefficient, because you are now doing two linear walks instead of one. Once walk through the data rows with the call to IndexOf, and a second one through the grid's Rows collection for GetRowWithListIndex. I see why this is not as efficient as your original suggestion. But when I tried to do it differently but I could not find any way to go from the DataRow to its index. I thought there would be a Index property on the DataRow that I could use. Any suggestions?
I see why this is not as efficient as your original suggestion. But when I tried to do it differently but I could not find any way to go from the DataRow to its index. I thought there would be a Index property on the DataRow that I could use. Any suggestions?
You probably have to do it this way if you are using a filtered DataView so that you get the correct index of the DataRow.
The alternative would be to walk through the grid rows and compare the grid row's ListObject with the DataRow you are looking for. This would be more code and might look like it's doing more work, but it's actually less, since it's only walking over the rows once.
Mike Saltzman"] That's good. But it's a bit inefficient, because you are now doing two linear walks instead of one. Once walk through the data rows with the call to IndexOf, and a second one through the grid's Rows collection for GetRowWithListIndex.
Thanks!
That's good. But it's a bit inefficient, because you are now doing two linear walks instead of one. Once walk through the data rows with the call to IndexOf, and a second one through the grid's Rows collection for GetRowWithListIndex.
But if it's working for you and it's giving you reasonable performance, then there's no reason not to use it. :)
Thanks Mike! That seems to have worked. I found that it could also been done as shown below as well.
UltraGridRow gridRow =
UltraGrid1.DisplayLayout.Rows.GetRowWithListIndex(table.Rows.IndexOf(DataRow));
Hi Adrian,
If you know the index of the row you can use the GetRowWithListIndex method on the Rows collection.
Otherwise, you will need to loop through the rows in the grid and examine the ListObject property of the row and compare it to the object you are looking for. If you are using a DataSet, keep in mind that the ListObject will return a DataRowView, not a DataRow - so be sure to get the Row propety from the DataRowView before you try to compare.