Hello,
I am working with a UltraWinGrid Control. The grid is bound to BindingList Collection which at beginning is empty. I want the user to type in some characters in a cell. Then press Enter and a Dialog is opened with a list that is filtered.
For example: ActiveCell is bound to DeviceSerialNumber and user enters "12" then the popup shows a list of devices containing "12" in the field SerialNumber.
Kind regards
Patrick
Hi Patrick,
Are you sure you want to make the users press Enter? The normal behavior for a dropdown is to show a list of suggestions as the user types. That will be a lot easier to implement and it's easier for the user since they don't have to do anything special to get the list to display.
To do it the way I suggested, all you have to do is attach a ValueList or UltraDropdown to the column and set the AutoCompleteMode to one of the "Suggest" options.
Patrick Jox said:I am starting with an empty grid which allows addnew. So in the addnew row the user enters "12" and <Enter>. The first problem is that the enter key is set to the next row. How can I avoid this? Actually I set it back to my edited row.
You would have to alter the KeyActionMappings collection of the grid and remove the mapping for the Enter key that has an action of CommitRow.
Patrick Jox said:Filtering does not work since UltrGridView.ActiveCell.Text does not return the value in the cell but the value of the bound member. Is there another property which returns the correct value?
I'm not sure what you mean by this. What you are saying here is exactly the opposite of how the grid works. The Text property of a cell will return what you see on the screen and it's the Value property that is not updated until you leave the cell.
Patrick Jox said:Is there a method to find out if the grid is in Addnew Mode afte´r having pressed <Enter>
There's a property on row for IsAddRow and also IsTemplateAddRow.
Patrick Jox said:My bound object is a complexe type with other Elements in say I have a position where I want to select the device only for infomation. The grid shows the expand icon in in front of the first column. I don't want the row to be expandable
I'm not sure I understand exactly what you are asking here, but it sounds like you want to set:
grid.DisplayLayout.ViewStyle = ViewStyle.SingleBand;
Mike,
Thanks for this. It helped me to achieve what I need. But I want to make the application more comfortable for the user so I would like to diable the enter behaviour only for two column? I think, this can't be done. right?
So I have to implement the move right after the user selected an Item from dialog manually. Is this done using activecell or do you have any prepared functions for this?
Regards
I'm sorry, but you lost me. What Enter behavior are we talking about?
You mean you went the Enter key to commit the row in some cells, but not in others?
In that case, what I would do is leave the KeyActionMapping at their defaults and then handle the BeforePerformAction event. You can see what the ActiveCell is and what action is being performed and then cancel the action only for certain cells.
Ok Just tried it. This works as long as I am adding a new row. After editing an existing row I do net receive the BeforePerformAction Event. I added my code below. I tried also to handle the ToggleEditMode Action but this comes to often.
e)
{
.Empty;
Model.
;
Model.Lists.
();
.ToggleEditMode)
)
filter =
.OrderGrid.ActiveCell.Text;
order =
r =
.Empty)
devices = r.GetDevices(
.ServiceCheque.Customer);
else
devices = r.GetDevicesBySerialNumber(filter,
(devices.Count == 1)
order.Device = devices[0];
}
form.ShowDialog();
.Cancel)
e.Cancel =
order.Device = form.SelectedDevice;
].Value = order.Device.SerialNumber;
].Value = order.Device.Name;
.OrderGrid.Refresh();
Maybe I should explain more what I am doing. I have list of Positions. A Position is containing a device which is not displayed directly. Instead I display Device.SerialNumber and Device.Name. I want give user the chance to enter part of SerialNumber. On enter I check Input against Database. If there is only one match, this item is taken. If there are more matches a list of filtered devices is shown in a separat dialog, where user can select what he meant.
Hope this points out what I mean?
You are right. I seem to have hooked the wrong event. I attached to KeyPress but called it "OnKeyDown". After your hint i checked the notation of my event handler and ...
Now it works fine.
Thank you.
Are you sure you are hooking the right event? KeyDown and not KeyUp or KeyPress?
I tried this out and in every case I can find, KeyDown fires before BeforePerformAction. That seems correct to me. If BeforePerformAction is firing first in some cases, then something may be wrong there.
Hi Mike,
the problem is, that the BeforePerformAction events fire before the KeyDown events. So I have to implement both. The BeforePerformAction event handler to suppress the CommitRow action. And the KeyDown event handler to perform my own action. Now this looks like following and it works.
private void OnBeforePerformAction(object sender, Infragistics.Win.UltraWinGrid.BeforeUltraGridPerformActionEventArgs e){
if (sender == this.OrderGrid) { switch (e.UltraGridAction) { case Infragistics.Win.UltraWinGrid.UltraGridAction.CommitRow: e.Cancel = true; break;
case Infragistics.Win.UltraWinGrid.UltraGridAction.NextCellByTab: if (this.OrderGrid.ActiveCell.Column.Key == "DeviceSerialNumber") e.Cancel = !PerformDeviceSerialNumberInput(); break; } }}
private void OnKeyDown(object sender, KeyEventArgs e){ if (e.KeyCode == Keys.Return) { if (sender == this.OrderGrid && this.OrderGrid.ActiveCell.Column.Key == "DeviceSerialNumber") { e.Handled = PerformDeviceSerialNumberInput(); } }}
As far as I can see. This meets all my requirements.
Thanks for your support.
Kind Regards
The grid only fires BeforePerformAction when the grid is handling a keystroke and doing something with it. The grid only handles Enter to commit the row when it's in an AddNewRow, I think. So the event won't fire for existing rows.
Perhaps what you should do is use the KeyDown. Then you can see what the ActiveCell is in the grid and do whatever you want. If you handle the keystroke by showing your dialog or filling in the cell's value, then you just have to set e.Handled to true and that should prevent the grid from handling that keystroke and committing the row.