I have a grid that is bound to an ultradatasource. I use the CellDataRequested event on the ultradatasource to populate it, along with populating the cell values for the row I also put a piece of data in the tag for the ultra data row.
This all works fine, except that once the grid has populated I want to select the first row, e.g. grid.Rows[0].Selected = true.
I thought I could do this from the CellDataRequested event for the first row (if e.Row.Index == 0 then grid.Rows[0].Selected = true.). This will obviously cause a AfterSelectChange to be fired on the grid, which is fine - except that if you look at grid.Selected.Rows[0] at this point although a row exists its cell values are empty, you can access the UltraDataRow for this gridrow, but it also has no values and more importantly (for what Im doing) the tag of the UltraDataRow is null.
It should be noted that this appears to be a time based problem - if I have a few breakpoints and spend a second or two on them and then continue the row will have values when it gets to the AfterSelectChange. Its like although I have populated the datasource it hasn't finished binding.
Basically what I need is some way of knowing that the first row has been populated so I can select it.
Any ideas?
Just a little clarification on this, when the grid initially populates its fine, but if the user changes the sort order I need to retrieve the data again - so on AfterSortChanged I clear the datasource and re-populate.. It is under these circumstances tha tthe above problem exists.
Ideally I want something like a AfterRowBound event so I know the grid row is populated.
Hi Mark,
There's no AfterRowBound event or anything like that, because binding does not end, it's a continuous process.
You could try using the InitializeLayout event of the grid, but you may still have the same problem with the empty ell values.
Another approach you might take would be to use the InitializeRow event. You could set a flag any time you know you have changed your data source. Then, in InitializeRow, you check for that flag and if it's true, you select the row being Initialize and then reset the flag so it only happens once.
If that doesn't work, then yet another thing you might try is to handle BeforeSortChange and set e.ProcessMode to Synchronous. This will make it so that AfterSortChange doesn't fire until the sorting is complete. But I don't think if this will do anything if you are using one of the External sorting modes, which it sounds like you are doing (or at least, it sounds like you should be doing this).
If all else fails, you could try calling grid.Refresh before selecting the row. That should force the grid to paint and thus get the values into the cells.
Hi Mike,
Thanks for the suggestions, I will take a look at using InitialiseRow.
For the moment just to continue I have stored the required tag on CellDataRequested in a form property, I then get it from there on the AfterSelectChange if its null on the selected row. Not very elegant, but it works.