Windows Develop Bookmark and Share   
 index > Windows Forms General > Set focus to a cell in the datagridview
 

Set focus to a cell in the datagridview

Hi,

I want to set focus to the last row and a particular column in the datagridview. When i use the following line, i do not see the focus or select property available?
How can i set the focus to that cell?

datagridviewnm.Rows(rowcount).Cells("column name")

Is there any other way to do this?

Thanks in advance

rowter  Friday, September 11, 2009 3:22 PM
Hi,
I hope it will help you..
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Selected = true;

Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
Gnanadurai  Friday, September 11, 2009 5:45 PM

Hi,

You can also set the currentCell property.

The following code will highlight two cells. If you set the editmode to editOnKeyStrokeOrF2 or EditOnF2, then press F2, currentcell (Rows(0).Cells(2) ) will begin edit.

dataGridView1.CurrentCell = dataGridView1.Rows(0).Cells(2)

dataGridView1.Rows(0).Cells(1).Selected = true

More information:

DataGridViewCell.Selected Property

Gets or sets a value indicating whether the cell has been selected.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.selected.aspx

DataGridView.CurrentCell Property

Gets or sets the currently active cell.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcell.aspx

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, September 14, 2009 9:43 AM
Hi,
I hope it will help you..
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Selected = true;

Best Regards, C.Gnanadurai ----------------------- Please mark the post as answer if it is helpfull to you
Gnanadurai  Friday, September 11, 2009 5:45 PM

Hi,

You can also set the currentCell property.

The following code will highlight two cells. If you set the editmode to editOnKeyStrokeOrF2 or EditOnF2, then press F2, currentcell (Rows(0).Cells(2) ) will begin edit.

dataGridView1.CurrentCell = dataGridView1.Rows(0).Cells(2)

dataGridView1.Rows(0).Cells(1).Selected = true

More information:

DataGridViewCell.Selected Property

Gets or sets a value indicating whether the cell has been selected.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.selected.aspx

DataGridView.CurrentCell Property

Gets or sets the currently active cell.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcell.aspx

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, September 14, 2009 9:43 AM

You can use google to search for other answers

Custom Search

More Threads

• Text resize on client's computer but not on mine
• Google-Chrome-like title bar
• system.windows.forms.timer help???
• TextBox validation after pressing the Enter or Return key
• Reposition mdi child form
• Apply animated gif with chat programe
• How To Get AssemblyName of the application
• A Few Queries :-)
• web browser control (WebBrowserControl) and history.
• pass string value to another form