This is a migrated thread and some comments may be shown as answers.

Cursor Focus on Filter when CellClick Event

7 Answers 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tommy
Top achievements
Rank 1
Tommy asked on 04 Feb 2009, 08:00 AM
Hi,

When a CellClick Event gets fired, I want to get the focus on the Filter of the Column where the user has clicked so that the user is able to directly type in Filter values.

How can I do that?

7 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 05 Feb 2009, 01:32 PM
Hi Tommy,

Thank you for this question.

You should call the BeginEdit method of the desired cell when processing the CellClick event. Consider the code snippet below:

void radGridView1_CellClick(object sender, GridViewCellEventArgs e) 
    if (this.radGridView1.CurrentRow is GridViewFilteringRowInfo) 
    { 
        this.radGridView1.CurrentRow.Cells[e.ColumnIndex].BeginEdit(); 
    } 

Do not hesitate to write if you need further assistance.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tommy
Top achievements
Rank 1
answered on 10 Feb 2009, 07:47 AM
Thanks for that Reply, i could us it even though it wasn't exactly what I was looking for.
I wanted to activate the FilterCell oft the Colum last clicked when the user presses a Key on the Keyboard and directly write the pressed Key as start in the FilterCell. In that case it would mean if the user has last clicket somewehre in Column 1 and hits the 'A' Key, then the Filter should be activated, have A set and the user should be able to conitue  writing.

It works fine now, except that I cannot set the pressed Key-Value.
What i did is the following:
 private void radGrid_CellClick(object sender, GridViewCellEventArgs e)  
        {  
            if (this.radGrid.CurrentRow is GridViewFilteringRowInfo)  
            {  
                this.radGrid.CurrentRow.Cells[e.ColumnIndex].BeginEdit();  
            }  
            this.currentColumn = e.ColumnIndex;  
        }  
 
        private void radGrid_KeyDown(object sender, KeyEventArgs e)  
        {  
            KeysConverter kc = new KeysConverter();  
            string keyChar = kc.ConvertToString(e.KeyData);  
            this.radrid.MasterGridViewInfo.TableFilteringRow.Cells[this.currentColumn].Value = keyChar;  
            this.radGrid.MasterGridViewInfo.TableFilteringRow.Cells[this.currentColumn].BeginEdit();  
        } 

How can i set the Value to the FilterCell and then call BeginEdit so that the user can continue with the starting Character already set?
0
Jack
Telerik team
answered on 10 Feb 2009, 10:23 AM
Hi Tommy,

You should process the PreviewKeyDown event in order to catch the key down in this case. I prepared a sample demonstrating this:

void radGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
    bool value = Console.CapsLock; 
    char key = (char)e.KeyValue; 
    if (!this.radGridView1.IsInEditMode  
        && char.IsLetterOrDigit(key)  
        && this.radGridView1.CurrentRow is GridViewFilteringRowInfo) 
    { 
        if (char.IsLetter(key) && !(Console.CapsLock || e.Shift)) 
        { 
            key = char.ToLower(key); 
        } 
        int index = this.radGridView1.Columns.IndexOf((GridViewDataColumn)this.radGridView1.CurrentColumn); 
        this.radGridView1.CurrentRow.Cells[index].BeginEdit(); 
        this.radGridView1.ActiveEditor.Value = key.ToString(); 
    } 


I hope this helps. Should you have any questions, feel free to ask.

All the best,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tommy
Top achievements
Rank 1
answered on 10 Feb 2009, 12:32 PM
Thanks again, this helped my pretty much, but I had to do it inside the KeyDown Event, ActiveEditor would still be null in afer BeginEdit() in the PreviewKeydown.

the last little problem, the Key Value gets now set, but when the user starts writing it gets added before the initaly set Key Value (the cursor is stil at position 0) instead of position 1 after the initialy set Value.

Regeards,
Tommy
0
Jack
Telerik team
answered on 11 Feb 2009, 01:41 PM
Hello Tommy,

I am glad to hear that we are getting closer to a solution for this issue. WinForms controls receive the KeyDown event only when the PreviewKey property of the Form is set to true. When it is set to false they receive the PreviewKeyDown event.

You could set the correct cursor position when processing the PreviewKeyDown event. Take a look at the code snippet below:

void radGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
    bool value = Console.CapsLock; 
    char key = (char)e.KeyValue; 
    if (!this.radGridView1.IsInEditMode 
        && char.IsLetterOrDigit(key) 
        && this.radGridView1.CurrentRow is GridViewFilteringRowInfo) 
    { 
        if (char.IsLetter(key) && !(Console.CapsLock || e.Shift)) 
        { 
            key = char.ToLower(key); 
        } 
        int index = this.radGridView1.Columns.IndexOf((GridViewDataColumn)this.radGridView1.CurrentColumn); 
        this.radGridView1.CurrentRow.Cells[index].BeginEdit(); 
        this.radGridView1.ActiveEditor.Value = key.ToString(); 
        RadTextBoxEditor textBox = this.radGridView1.ActiveEditor as RadTextBoxEditor; 
        if (textBox != null
        { 
            textBox.SelectionStart = textBox.Text.Length; 
        } 
    }  

Please write me back if you have more questions.

All the best,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tommy
Top achievements
Rank 1
answered on 16 Feb 2009, 08:26 AM
Thanks again, all works fine now for Text Filters, the last little problem is with the GridSpinEditor vor Number Filters. There I can't set the SelectionStart and the problem is the same as before with the Text Filter.
0
Jack
Telerik team
answered on 16 Feb 2009, 11:57 AM
Hi Tommy,

Thank you for writing me back.

You should do a little trick in case of a spin editor. The GridSpinEditor control does not expose its text editor item. You have to access it through the Children hierarchy. Take a look at the sample below:

void radGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
    bool value = Console.CapsLock; 
    char key = (char)e.KeyValue; 
    if (!this.radGridView1.IsInEditMode 
        && char.IsDigit(key) 
        && this.radGridView1.CurrentRow is GridViewFilteringRowInfo) 
    { 
        int index = this.radGridView1.Columns.IndexOf((GridViewDataColumn)this.radGridView1.CurrentColumn); 
        this.radGridView1.CurrentRow.Cells[index].BeginEdit(); 
        this.radGridView1.ActiveEditor.Value = int.Parse(key.ToString()); 
        GridSpinEditor spinEditor = this.radGridView1.ActiveEditor as GridSpinEditor; 
        RadTextBoxItem textItem = (RadTextBoxItem)spinEditor.Children[2].Children[1]; 
        if (textItem != null
        { 
            textItem.SelectionStart = textItem.Text.Length; 
        } 
    }   

Should you have any questions, do not hesitate to ask.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Tommy
Top achievements
Rank 1
Answers by
Jack
Telerik team
Tommy
Top achievements
Rank 1
Share this question
or