DataGridview Text box cell focus

  • 9 years ago


         How to set the cursor focus(Blinking cursor) on the DataGridView Text box Cell in C#.Net.Thanks in advance.

  • 9 years ago

    Hi Kumar, 

    You can do this thing in two ways:

    1) When you have set the datasource of the grid and executed GridName.DataBind(). Then there is event of the grid as ItemDataBound. You need to map the e object of the method agrument to the cell position where your textbox is. Then declare a textbox object and cast it with the object position found as FindControl like this:

    TextBox txtTemp = new TextBox(); 

    txtTemp = (TextBox)e.Items.Cells(0).FindControl("txtName");

    soon you have that object casted in the txtTemp then set the focus in it.

    If (txtTemp != null)

    { txtTemp.Focus(); }

     2) If you have already populated the grid, then loop through the grid and retrieve the row object of the looped row. Find the mapped position as above and set the focus.



  • 9 years ago

     Hi Moiz

            Thanks for your quick reply.I will apply it and let you know.

    With thanks



Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov