Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:20:04+00:00 2026-05-31T08:20:04+00:00

I have a Windows Form VS2010 .NET 4 project with a standard DataGridView bound

  • 0

I have a Windows Form VS2010 .NET 4 project with a standard DataGridView bound to a datasource on a form.

The grid has a text column that I want to be a point and edit at the character clicked to.
Like normal textbox/editors when you click on the character you want to adjust. If possible I would also like to use the UP/DOWN keys to move between rows but would like the cursor to move to the same character position obviously in the same column without selecting the entire text.

I have tried a few things:

DataGridView1.ClearSelection()

DataGridView1.BeginEdit(False)

The BeginEdit just puts the cursor at the end of the text, which means another click to point to the character position for editing.

I know a Commercial grid like DevExpress defaults to editing in which you can click to the correct character position with one click but obviously costs money.

I have tried in the DataGridView1_EditingControlShowing event

If TypeOf e.Control Is System.Windows.Forms.DataGridViewTextBoxEditingControl Then
        Dim tb As TextBox = e.Control
        tb.SelectionStart = 5
        tb.SelectionLength = 5
End If

But this does nothing.

I am just trying to remove the two or three clicks to get to the character position that needs adjustment.

I haven’t looked at a Custom DataColumn as yet.

Any suggestions would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:20:06+00:00Added an answer on May 31, 2026 at 8:20 am

    There is no good out of the box way of doing this. The closest there is is to set the EditMode of the grid to EditOnEnter but that means you only need two clicks, not three.

    You will need to write your own column type.

    Someone has done just that here.

    I haven’t checked if that example handles up and down – if it doesn’t then you were on the right track with the SelectionStart and SelectionLength properties, just grab the caret position of the cell you are leaving and apply it to the new cell.


    It turns out that setting these properties is a little bit more involved that I remembered (possibly because I was already using a MaskedTextBox custom column type last time I did this).

    The code below (in c# but the principle holds for vb.Net and I can give the vb code if you can’t convert it yourself) works happily – could be tidied up by putting it into a custom control but I’ll leave that as an exercise 🙂

    First I add a handler for the EditingControlShowing event:

    void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        DataGridViewTextBoxEditingControl t = e.Control as DataGridViewTextBoxEditingControl;
        current_control = t;
        t.Leave += new EventHandler(t_Leave);
    }
    

    In the method above current_control is a form level private variable. The event handler for t looks like this:

    void t_Leave(object sender, EventArgs e)
    {
        cell_caret_pos = current_control.SelectionStart;
    }
    

    There again we have a class level private field – cell_caret_pos.

    Then what I found was that to set SelectionStart and SelectionLength you need to work within the CellEnter event handler:

    private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
    {
        dataGridView1.BeginEdit(false);
        DataGridViewTextBoxEditingControl editControl =
            (DataGridViewTextBoxEditingControl)dataGridView1.EditingControl;
    
        if (cell_caret_pos != 0)
        {
            editControl.SelectionStart = cell_caret_pos;
            editControl.SelectionLength = 0;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form with a DataGridView control. I bound it into an
I have a windows form for a desktop app that has 7 fields, how
I have a Windows Form that takes quite a bit of time to load
I have a windows form application that uses a Shared class to house all
I have a windows form on the main thread and another thread that does
I have a Windows Form application. Version 1 of my app has been released
I have a windows form with DataBound DataGrid on it. Bound to a list
I have a simple windows form with a statusStrip in VS2010, and no matter
I have a Windows Form with data bound textBox which displays a phone number
I have a windows form which has 1 button (for simplicity). On clicking this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.