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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:35:03+00:00 2026-05-25T02:35:03+00:00

I have a DataGridview with several columns, and one of the column is DataGridViewComboBoxColumn.

  • 0

I have a DataGridview with several columns, and one of the column is DataGridViewComboBoxColumn.

The scenario is, When the user selects some value from the combobox (selected index > 0), the whole row of the selected cell will be shown in white. If the user selects the empty value for the combobox (selected index is 0) then the whole row will be shown in Yellow, and this combobox cell should be shown in Red.

I could able to achieve showing the whole row in yellow except for the combobox column.

private void grdCurve_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            //for datatype column
            if (grdCurve.CurrentCell.ColumnIndex == DATATYPE_COLUMN_INDEX)
            {
                // Check box column
                ComboBox comboBox = e.Control as ComboBox;
                comboBox.SelectedIndexChanged -= new EventHandler(comboBox_SelectedIndexChanged);
                comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
            }
        }

void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
        if (selectedIndex >= 0)
            {
            if (!ValidateMnemonic(mnRow, row))
                {
                    MarkInvalidRow(row);
                }
                else
                {
                    MarkValidRow(row);
                }
            }
        }

private void MarkInvalidRow(DataGridViewRow row)
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            if (m_InvalidRowTable.Count > 0)
            {
                if (m_InvalidRowTable.ContainsKey(row.Index))
                {
                    int col = Convert.ToInt32(m_InvalidRowTable[row.Index]);
                    DataGridViewCell cell = row.Cells[col];
                    MarkInvalidRowColor(row);
                    style.BackColor = Color.Red;
                    style.SelectionBackColor = Color.Red;
                    cell.Style = style;
                    if (grdCurve.CurrentCell is DataGridViewComboBoxCell)
                    {                        
                        grdCurve.CurrentCell.Style = style;
                    }
                }
                else
                {
                    MarkInvalidRowColor(row);
                }
            }
            else
            {
                MarkInvalidRowColor(row);
            }

            m_InvalidRowTable.Remove(row.Index);
        }

private void grdCurve_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            //do nothing  
        }

private void grdCurve_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (grdCurve.CurrentCell is DataGridViewCheckBoxCell)
                grdCurve.CommitEdit(DataGridViewDataErrorContexts.Commit);

            if (grdCurve.CurrentCell is DataGridViewComboBoxCell && grdCurve.IsCurrentCellDirty)
                grdCurve.CommitEdit(DataGridViewDataErrorContexts.Commit);

            grdCurve.EndEdit();
        }

When i change the item in the combobox to empty, I expect the combobox to be marked in red color.
But, it shows in white and when i click on some other cell, the red color gets updated in the combobox cell.

Please help.

Thanks,
Prasad

  • 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-25T02:35:03+00:00Added an answer on May 25, 2026 at 2:35 am

    Take a look here http://msdn.microsoft.com/en-us/library/1yef90x0.aspx theres is a section entitled setting cell styles dynamically. You should implement a handler for DataGridView.CellFormatting

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

Sidebar

Related Questions

I have datagridview with checkbox column, but I want, that some of the columns
I have a DataGridView with several columns and several rows of data. One of
I have DataGridView with two columns. The first column is TextBoxCol(DataGridViewTextBoxColumn) and the Second
I have a DataGridView with a DataGridViewComboBoxColumn in the first column that is bind
I have datagridview which fills data from database, there are columns where I have
I have a DataGridView with some columns in it. For example I have the
I have a DataGridView (datagridview2) with several columns of data. I have a local
I have a DataGridView that has three read only columns in it and one
I have a DataGridView and I need to add several (say 20) columns to
I have DataGridView which contains two ComboBox columns. The second ComboBox will be filled

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.