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
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.
Hi Patrick,
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.
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?
Regards