We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridGroupingControl select a cell and set the cursor position or highlight the value


Hello, I would like to be able to select a cell in my grid grouping control and set the cursor position (second image below) or highlight the cell value (third image below).

I have the code below, but it only selects the cell and does not achieve what I want (first image below):

Record record = GetRecord(id);
record.ParentTable.CurrentRecordManager.CurrentField = gridGroupingControl1.TableDescriptor.Fields[2];
record.SetCurrent();

Can you please let me know what I would have to do to get the code to work like the 2nd and 3rd screenshots (I did those manually but would like to know how to do them programatically)?

Thanks for your help!



4 Replies

TT tttmack July 6, 2015 11:48 PM UTC



NK Neelakandan Kannan Syncfusion Team July 7, 2015 11:27 AM UTC

Hi Taylour,

Thank you for using Syncfusion products.


Query-1
How can I get the code to select the cell with cursor blinking at the end position?


If you want to set the record with cursor at end position of the cell, you can use the CurrentCell.MoveTo method instead of using SetCurrent method of record. After moving the CurrentCell to particular cell, you can set the cursor at end position by using CurrentCell.Renderer. Please make use of below code,


Code Snippet:

private void moveBtn_Click(object sender, EventArgs e)

{

//Set your needed column index

int colIndex = this.gridGroupingControl1.TableDescriptor.FieldToColIndex(0);


//Getting the record rowIndex based on its position

int rowIndex = this.gridGroupingControl1.Table.Records[0].GetRowIndex();


//Moving the current cell

this.gridGroupingControl1.TableControl.CurrentCell.MoveTo(rowIndex, colIndex, Syncfusion.Windows.Forms.Grid.GridSetCurrentCellOptions.SetFocus);

this.gridGroupingControl1.Focus();


//Setting the cursor at end position of cell

if (this.gridGroupingControl1.TableControl.CurrentCell.Renderer is GridTextBoxCellRenderer)

{

GridTextBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridTextBoxCellRenderer;

renderer.TextBox.SelectionStart = renderer.TextBox.Text.Length;

}

}



Query-2
How can I get the code to highlight the CellValue?


If you want to highlight the cellvalue in cell, you can use renderer.TextBox.SelectAll() method instead of using renderer.TextBox.SelectionStart.


Code Snippet:

//Highlighting the cellvalue

if (this.gridGroupingControl1.TableControl.CurrentCell.Renderer is GridTextBoxCellRenderer)

{

GridTextBoxCellRenderer renderer = this.gridGroupingControl1.TableControl.CurrentCell.Renderer as GridTextBoxCellRenderer;

renderer.TextBox.SelectAll();

}


Note:
In the below sample, we have provided the two buttons. If you press the “Moving with cursor at end” button, the currentcell will be moved to particular cell with cursor at end position. The currentcell will be moved with highlighting the cellvalue if you press the “Moving with CellValue highlighting” button.

Sample:
http://www.syncfusion.com/downloads/support/forum/119541/ze/Sample_CurrentCell_Move-686832298

Please let me know if you have any queries.

Regards,
Neelakandan


TT tttmack July 9, 2015 02:54 AM UTC

thank you very much for your help Neelakandan!


NK Neelakandan Kannan Syncfusion Team July 9, 2015 04:11 AM UTC

Hi Taylour,

Thank you for your update.

We are glad to hear from you that your reported scenario has been achieved.

Please let us know if you need further assistance on this.

Regards,
Neelakandan

Loader.
Live Chat Icon For mobile
Up arrow icon