Hi,
OnListChanged(ListChangedType.ItemAdded, TargetCount-1);
We do see the new row in the grid. The problem is that we would like to perform some actions when adding a new row to the grid and AfterRowInsert is does not seem to be working.
What have we missed?
As always, thank you in advance.Annie
> int listIndex = dataTable.Rows.IndexOf(dataRow);> this.ultraGrid1.Rows.GetRowWithListIndex(listIndex);
That's what I was looking for. Thanks!
If you add a new row to your data source, then you presumably have a reference to the new row from the data source. So, for example, if you are using a DataTable and add a new row, you have the DataRow. If you want to then find that row in the grid, you can do that very easily.
In almost all cases, the new row will will be added to the bottom of the rows collection. So you can just get the last row in the grid:
this.ultraGrid1.Rows[this.ultraGrid1.Rows.Count - 1]
Of, if you are concerned that this might not always be accurate, then you can get the rows using the index of the data source row in the list.
int listIndex = dataTable.Rows.IndexOf(dataRow);this.ultraGrid1.Rows.GetRowWithListIndex(listIndex);
Late to this party, but a one case would be adding an entry to a data source, but handling the Grid's reaction to that change on the UI side.
For instance, if I insert a data source row programmatically, which then results in a new UltraGridRow being created, and I want to highlight/format/focus that row, I would need to determine which UltraGridRow was just created. While I could do this by searching the underlying bound object, this is potentially time consuming. By having direct access to the UI elements, I could perform operations without having to do an additional lookup step.
Obviously the creation of the UltraGridRow is happening... it would just be nice if an event was exposed to let us know it was happening.
Events fire to let you, the developer, respond to actions that the user takes. If you are adding a row to your data source directly, then you know you did it and you do not need an event to tell you that it happened.
In fact, many controls fire events regardless of whether the action is triggered by a user or by code, and there's no real hard and fast rule about when events will and will not fire. But I would not consider this a bug.
In this case, the data source will fire a notification and the grid is a consumer of the event. It would not make sense for the grid to re-fire the event or to fire a new event in response to the event notification it is consuming.
What I would do is either change your code to add the row through the grid - or else move the code from AfterRowInsert into a helper method and call that helper method from the AfterRowInsert event and also from your code where you are adding a row to the data source.
Yes you are right i am adding the row in my datasource. Is their any way out to capture this event while adding new row in data source? Is this the way the grid have to behave or its a bug in the control or missing functionality?