DataGridview Text box cell focus

  • 9 years ago

     Hi

         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.

    Regards,

     Moiz

  • 9 years ago

     Hi Moiz

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

    With thanks

    Kumar
     

       
     

Post a reply

Enter your message below

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

Contribute

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.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra