.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

how to set focus of the cell of gridview

Posted By: Santosh     Posted Date: October 19, 2010    Points:2   Category :Windows Application
hi all,

can any body plz tell me how to set focus of cells of gridview.

Ex: There are 10 rows and 5 columns of my grid view .
out of 5, first 3 columns are read only,
so after entering the value of 5 th column/cell of 1st row ,if i click tab then fucus should goes to 2nd rows of 4th column.

i m working on windows application and vb.net


Author: Jean Paul             
Posted Date: October 22, 2010     Points: 5   

You can use: gridView.Rows[0].Cells[0].Selected = true;

For moving tab focus: you have to write code in the KeyDown event of grid view:
Keys.Tab filters the current key stroke as Tab character

private void gridView_KeyDown(object sender, KeyEventArgs e)
if (e.KeyCode == Keys.Tab)
// Get the next valid cell
// Call the focus

Sorry for that I do not have VB.NET installed.

Jean Paul http://jeanpaulva.com/
Author: Santosh             
Posted Date: October 26, 2010     Points: 5   

Thanx,i got the Code for this


Author: Santosh             
Posted Date: October 26, 2010     Points: 5   

Private Sub dgvDisplay_CellEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDisplay.CellEnter

Dim dgvDisplay As DataGridView = DirectCast(sender, DataGridView)
' Check for disabled. If so the force move to next control
If dgvDisplay.Rows(e.RowIndex).Cells(e.ColumnIndex).ReadOnly Then
End If
End sub


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend