Hi, I have an UltraCombo bound to an UltraGrids cell. While the cell is multiline, my users can edit a good portion of text in the cell. When using the ultracombo the users can select a string from a list of strings. This string will be copied into the cell and the users can edit this text. Now - when the users tries to navigate through the edited text with the arrow keys, he actually navigates through the ultracombos entries and the edited text is replaced by the string selected from the combox in an instant. How can i prevent the ultracombo from scrolling through the rows when hitting arrow keys?
Thanks for all helpful answers.
Hello,
A possible approach to achieve this might be by using the following code sample:
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { if (ultraGrid1.ActiveCell.Column.Key == "Column 0") { if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) { e.Handled = true; } } }
Please feel free to let me know if I misunderstood you or if you have any other questions.
Hi,
thanks for your answer. The good thing is, the solution will prevent, that the user accidentially overwrites the edited text. The bad thing is, he can't navigate through the edited text with arrow keys. What would be the perfect solution.
Can I handle the keydown event for the arrow keys in the way, that the cursor switches the lines within the editorcomponent but without letting the ultracombo select the next row?
Hi Martin,
I might have missed this requirement.
You could divide the 'if' statement into two - if Down and if Up. Then you could use:
ultraGrid1.ActiveCell.SelStart += 1;
and
ultraGrid1.ActiveCell.SelStart -= 1;
Sample:
if (e.KeyCode == Keys.Down) { ultraGrid1.ActiveCell.SelStart += 1; e.Handled = true; }
Please feel free to let me know if a question about our tool set comes up on your mind.
Actually with that solution i can move the cursor a position when pressing the arrow key. Is it possible to get the normal reaction for pressing the arrow key? Namely, that the cursor moves up or down a line?
Oooh, now I get it! Could you please try the following code sample:
if (e.KeyCode == Keys.Down) { string[] lines = ((Infragistics.Win.UltraWinGrid.UltraGridComboEditor)(ultraGrid1.ActiveCell.EditorResolved)).TextBox.Lines; EmbeddableTextBox tb = ((Infragistics.Win.UltraWinGrid.UltraGridComboEditor)(ultraGrid1.ActiveCell.EditorResolved)).TextBox; int line = tb.GetLineFromCharIndex(tb.SelectionStart + tb.SelectionLength); tb.SelectionStart += lines[line].Length + 2; e.Handled = true; }
Yeah, thats the solution i was looking for!
Actually, it was a bit tricky to find out the difference between up and down, but now i got it:
string[] lines = ((EditorWithText)(grdForecast.ActiveCell.EditorResolved)).TextBox.Lines;EmbeddableTextBox tb = ((EditorWithText)(grdForecast.ActiveCell.EditorResolved)).TextBox;int line = tb.GetLineFromCharIndex(tb.SelectionStart + tb.SelectionLength);if (e.KeyCode == Keys.Down) tb.SelectionStart += lines[line].Length + 2;else tb.SelectionStart -= lines[line-1].Length + 2;
Thanks for your help, Boris!
Martin,
Honestly, I forgot about the up arrow but I see that you know have it all working!