I have a UltraGrid column of type string.
I set a ValueList property of the UltraGridColumn that I get through the UltraGrid's DisplayLayout.
After the user selects an item in the drop down, the grid puts the cursor in the cell to allow editing.
The user has to hit 'ENTER' after selecting the drop down for the edit to raise the change event.
How can I make the change event get raised when the selection finishes with out requiring the user to also hit enter...
I want the edit applied on the select and the change raise immediately...
yes this lets the user select the date item from the list and immediately sets the property of the item in binding list on user click in the ValueList.
Thanks!
m_grid.CellListSelect += new CellEventHandler(Grid_CellListSelect);...
void Grid_CellListSelect(object sender, CellEventArgs e){ if (null == e.Cell.Column.ValueList) return;
// force data commit on list item click // do not wait for the // default edit behavior // of waiting for the user to hit 'ENTER' e.Cell.Row.Update(); }
Hi Karl,
metavr said:to clarify - I receive the event from the ultragrid when a bound record has is poperty set. In turn I raise events to notify the rest of the system of the change.
I still don't know what event you are referring to. But I don't think it matters.
If you know that the user must select from the list and that every choice that can make is always valid, then you could force the grid to commit the changes. What you would do is handle CellListSelect or CellChange in the grid and trap for changes in that one particular column (or columns) and then you can force the grid to commit the changes by calling Update on the row.
The problem with this is that it will commit all changes in the row, not just the one for this particular column. This is probably not a big deal, since the grid probably committed the change to any other cells in the same row when the user left that cell, anyway.
Hello Karl,
After reading Mike's post and yours, I believe that the CellListSelect event is your best option. Please let us know if you have any other questions about this.
"I'm really not sure what event you are referring to. There is no Change event on the grid. Are you asking about a grid event or an event on some other object?"
to clarify - I receive the event from the ultragrid when a bound record has is poperty set. In turn I raise events to notify the rest of the system of the change.
This causes other parts of the UI to update.
this.ultraGrid1.DataSource = new BindingList<MyRecord>(_recordList)
where
class MyRecord{
string _weapon;
public string WeaponColumn {
get { return _weapon; }
set { _weapon = value;
// notify the rest of the system from here
}
"The grid doesn't commit the changes to a cell on every keystroke or when you pick from the list, because that would be very inefficient and dangerous. The user might change his mind and pick something else and so any processing you do at that point would have been wasted."
It depends on what is in the cell and the expected user interaction.
In my case the ValueList is a list of atomic items. In the currently implementation, the user has to select from a drop down with the mouse, and then reach back with the key board and press 'ENTER' with the keyboard to confirm that yes in fact he really did mean it when he clicked the drop down with the mouse. From the user perspective, selecting from the drop down should trigger the update, with no extra confirming 'ENTER'. We know that the data is valid because he just selected it from the dropdown.
"There is also a CellListSelect event on the grid. This is similar to CellChange, in that the Value property will not have been updated when it fires and you have to use Text."
ok I will explore taking the notify out of the record set and hijacking using this as a work around.
Thanks
Karl
Hi,
I'm really not sure what event you are referring to. There is no Change event on the grid. Are you asking about a grid event or an event on some other object?
The grid doesn't commit the changes to a cell on every keystroke or when you pick from the list, because that would be very inefficient and dangerous. The user might change his mind and pick something else and so any processing you do at that point would have been wasted.
Also, for some types of cells, updating on every change would not work. Take, for example, a DateTime cell. As the user is typing, what they type initially isn't a valid date at all, until they type a certain number of characters.
There's a CellChange event on the grid that fires on every keystroke (or when you select a ValueListItem) but the Value of the cell will not (and really cannot) reflect the change at this point, since it might not be valid. You have to use the Text property of the cell to get the actual on-screen text of the cell.
The grid writes changes to the data source based on the UpdateMode property. By default, this happens when you leave the cell or the grid control loses focus.
If you want to force an update manually, you can call the UpdateData method on the row (to commit all changes in the row) or the Update method on the grid (to commit all changes to all rows). But, of course, this method can fail in some cases if the user is in the middle of editing. That's probably not a problem in this case.
There is also a CellListSelect event on the grid. This is similar to CellChange, in that the Value property will not have been updated when it fires and you have to use Text.