0

Consider a Farpoint spread control containing multiple columns and rows. On Entering/Pressing multiple alphabetical keys,it should select the row which has entered combination of words.

Example:If 'a','n','u' is typed it should automatically select the row with name anusha. If 'j','a' is typed it should automatically select the row related to that combination(jack,jane,etc).

when I use the below code,value of keyChar is always single character(a,b,c,..).If I try typing 'a','n','u', the it is not displaying anusha. It is displaying some other name starting with a(ambi),then n(nisha) and then u(uma) in this order.This is because keypress event is called every single time a key is pressed. Now my concern is how to make keyChar accept strings?

private void Keypress(object sender,KeyPressEventArgs e)
{
    If(e.KeyChar != (char)Keys.Enter && e.KeyChar != (char)Keys.Escape)
    {
        ABCFunction.SpreadKeyAction(SftTaskTree, e.KeyChar.ToString(), Name_Col_Pos);
    }
}

I tried using variable to store and pause the thread for particular time. Even this is not working since everytime it enters the 'if' loop and makes the stored variable empty.

private void Keypress(object sender,KeyPressEventArgs e)
{
       store = store + e.KeyChar.ToString();
       Thread.Sleep(1500);
       If(e.KeyChar != (char)Keys.Enter && e.KeyChar != (char)Keys.Escape)
       {
          ABCFunction.SpreadKeyAction(SftTaskTree, store , Name_Col_Pos);
          store = String.Empty;
       }
}

Please anyone help with this...

SUJITHA M
  • 1
  • 1
  • Your second example still passes the pressed character to the control rather than your `store` variable? – stuartd Nov 20 '19 at 11:41
  • Actually, when I press 'a','n','u' after 1.5 sec for each character(i.e- 'a') 'If' loop is iterated and when store =String.Empty line is hit ,then store='' ".when I comment the store =String.Empty line,then it is storing 'anu' for the first time and the when you type any other word 'sam' then it stores 'anusam'. – SUJITHA M Nov 20 '19 at 12:23
  • What I meant was you're calling `ABCFunction.SpreadKeyAction` with `e.KeyChar.ToString()` rather than `store`, which is what I thought you would want to do? But I'm not familiar with the controls you're using, so I'm probably wrong! – stuartd Nov 20 '19 at 12:51
  • Sorry about that. It was a mistake.Now I edited my question. – SUJITHA M Nov 20 '19 at 12:54
  • OK, that makes more sense. So what I think you have to do is decide _when_ to clear `store`. Perhaps if the escape key is pressed, in which case you would change `Keypress` to only clear `store` when the user presses escape? You probably also want to clear it if the user clicks or selects something on the control. – stuartd Nov 20 '19 at 14:37

0 Answers0