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 6949905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:01:05+00:00 2026-05-27T14:01:05+00:00

I use DataGridView that gets Data from DataTable for editing some amount of data.

  • 0

I use DataGridView that gets Data from DataTable for editing some amount of data. Everything seems ok, but there is some inconvenience. When user starts to edit cell, text of this cell automatically become selected and cursor moves to the end of cell text.
I want to place cursor(caret) to the start of the text in editing cell programmatically when user starts to edit cell text.
I tried:

private void gridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        DataGridViewTextBoxEditingControl dText = (DataGridViewTextBoxEditingControl)e.Control;
        dText.Select(0, 0);
    }

That is not work. Also I tried to deselect text in CellBeginEdit- also no result.

  • 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-27T14:01:06+00:00Added an answer on May 27, 2026 at 2:01 pm

    I would have expected what you did to work too. But the DataGridView is a complex control with many events and often it doesn’t work intuitively. It seems that when the EditingControlShowing event happens, the control hasn’t been initialized yet, so you can’t affect it. And when the CellBeginEdit event happens, the control hasn’t even been created yet.

    There should be and probably is a better way to do it, but I got it to work using the CellEnter event:

    private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
    {
        if (dgv.CurrentCell.EditType == typeof(DataGridViewTextBoxEditingControl))
        {
            dgv.BeginEdit(false);            
            ((TextBox)dgv.EditingControl).SelectionStart = 0;
        }
    }
    

    So when the cell is entered I just go straight into edit mode, but I pass false to BeginEdit() which tells it not to select any text. Now the edit control is fully initialized and I can set SelectionStart to zero to move the cursor to the start of the text.

    If the cell isn’t a textbox then I do nothing.

    If you want you can do

    dgv.EditMode = DataGridViewEditMode.EditProgrammatically;
    

    so that you have full control over when editing begins, but I find this isn’t necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have an application that I want to display some data from
I have this problem: I have a datagridview that reads the data from a
I have a DataGridView that I want to use to store generic data. I
For C# Window Form, there is a tool called DataGridView. If we use that
I have a DataTable which is bound to datagridview (Winforms)... I use the following
I'm trying to create a windows form application that manipulates data from several tables
I have a Datagridview in my C# program that contain numeric data. I need
I've just started to use dataGridView, and some things seem strange to me: when
I'm trying to delete a row from a DataGridView I use two types of
I'm writing a Windows Form Application, that makes extensive use of datagridview and others

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.