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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:55:22+00:00 2026-06-11T18:55:22+00:00

I have a DataGridView that I want users to be able to add records

  • 0

I have a DataGridView that I want users to be able to add records to directly. This is done by clicking a link beneath the DGV, at which point a new row is programmatically added, and the first visible cell is of ComboBoxCell type. Code excerpt for how I’m doing this is:

// Add a new row to DGV
DataGridView dgv = this.dgvInformation;
DataGridViewRow newRow = new DataGridViewRow();
dgv.Rows.Add(newRow);

// Create cells and add to row
DataGridViewComboBoxCell cellInfoType = new DataGridViewComboBoxCell();
newRow.Cells["InfoType"] = cellInfoType;

// Create DataSource based off LINQ query here
List<ComboItemAccountInfoType> comboDataSource = new List<ComboItemAccountInfoType>();
// List is populated here

// Assign DataSource to combo cell
cellInfoType.DataSource = comboDataSource;
cellInfoType.ValueMember = "AccInfoTypeID";
cellInfoType.DisplayMember = "InfoType";

// Scroll new row into view and begin editing
dgv.FirstDisplayedScrollingRowIndex = dgv.Rows.Count - 1;
dgv.CurrentCell = dgv[1, dgv.Rows.Count - 1];
dgv.BeginEdit(true);

The DataSource contains some values with an ID of -1, which are categories that the user should not be able to select, and all other values have their valid database ID. This all works fine, except that if a user has selected a -1 row I am unable to keep the combo cell in edit more, as it simply stores the value in the cell and I can no longer activate the drop-down. I have added the following code to the _CellValueChanged event, but it has no effect:

private void dgvInformation_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    DataGridView dgv = this.dgvInformation;
    DataGridViewCell cell = dgv[e.ColumnIndex, e.RowIndex];

    // If type of cell is ComboBox then 
    if (cell.GetType() == typeof(DataGridViewComboBoxCell))
    {
        DataGridViewComboBoxCell cellInfoType = (DataGridViewComboBoxCell)cell;

        if ((int)cellInfoType.Value == -1)
        {
            MessageBox.Show("Going back into edit mode...");
            dgv.CurrentCell = cell;
            dgv.BeginEdit(true);
        }
        else
        {
            MessageBox.Show(cellInfoType.Value.ToString());
        }
    }
}

I do get the “Going back into edit mode…” message here after moving onto another cell, but it doesn’t then do what it says! Could anyone please explain why it won’t go back into edit mode, or is there a way of preventing the value becoming locked as soon as it has been selected?

Many thanks!

  • 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-06-11T18:55:24+00:00Added an answer on June 11, 2026 at 6:55 pm

    There should be a “validating” event for you to intercept and cancel if the value is -1.

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

Sidebar

Related Questions

I have a virtual datagridview that I want to set varying row heights for.
I have created a binded DataGridView that has one single column. I want to
I have datagridview with checkbox column, but I want, that some of the columns
Is this good practise? I have 3 DataGridView's and I want to have a
I have a DataGridView that uses databinding, with manually created columns, and this works
Let's say I have a DataGridView Control that displays about 100 records of a
I have a Database table that I want to display in a DataGridView. However,
I have a DataGridView that I'm feeding a List The DataGridView is populating perfectly,
I have a DataGridView that is bound to a list of objects called BaseChange.
I have a datagridview that may or may not have rows selected when the

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.