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
Hi Annie,
This is correct. AfterRowInsert fires to let you know when the user has added a new row. If you are adding the new row in code or if it is occurring as the result of some other action, then you already have a way of determing that it happened, and you don't need a grid event to tell you so.
You should probably trap the ListChanged event of your data source and use that. Or perhaps expose another event on your data source to indicate after the row has been added.
Hello Mike,
In my specific scenario, I am counting on the grid receiving the notification that a row was added.
So if you have any clues as to why the event is not firing, please let me know and I will investigate. I would like to avoid using the workarounds you provided if possible.
Many thanks,
Annie
As I said, I think this is probably intentional. Your data source already fires an event for this and since it does, there's no reason for the grid to duplicate the event.
You might try the PropertyChanged event of the grid and see if that fires, but I suspect it won't.
Hi Mike,
Well i m also facing the same prob but my scenario is different. I have constructed my own custom control inherited from UltraGrid, now i am placing my Custom grid on different form, but their is a common functionality i want to achieve on all the forms, after new row insert in the grid. I have register this event _AfterRowInsert but i didn't fire. Can you please describe why it is not firing?
Thank You
> 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?