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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:27+00:00 2026-05-26T20:11:27+00:00

I have a datagridview with a bound combobox column which contains decimal value. There

  • 0

I have a datagridview with a bound combobox column which contains decimal value. There is a range of valid decimal values so user can choose one of them. However I face a strange problem – when you click on a combobox in the selected value somehow resets to the first one in a list thus losing the one already selected. Look at the pictures

This is the initial view of a window:

enter image description here

This is when I select similar column with a double value in it(note the selection in combobox’s list)
enter image description here

This is when I select column with a decimal value. The selection(number 293) is missing

enter image description here

Here is the code I use:

        public Form1()
        {
            InitializeComponent();

            dgwResult.AutoGenerateColumns = false;
            var list = new List<string>(){"A", "B", "C", "D"};
            var list2 = new List<double>();
            var list3 = new List<decimal>();
            for (int i = 0; i < 300; i++)
            {
                list2.Add((double)i);
                list3.Add((decimal)i);
            }
            dgw_2.DataSource = list;
            dgw_2.DataPropertyName = "two";
            dgw_3.DataSource = list2;
            dgw_3.DataPropertyName = "three";
            dgw_4.DataSource = list3;
            dgw_4.DataPropertyName = "four";
            DataTable dt = new DataTable();
            dt.Columns.Add("one", typeof(string));
            dt.Columns.Add("two", typeof(string));
            dt.Columns.Add("three", typeof(double));
            dt.Columns.Add("four", typeof(decimal));
            dt.Rows.Add(new object[] { "akjsgdf", "A", 10.0, 10.0m });
            dt.Rows.Add(new object[] { "akjsgdf", "B", 15.0, 15.0m });
            dt.Rows.Add(new object[] { "akjsgdf", "C", 20.0, 20.0m });
            dt.Rows.Add(new object[] { "akjsgdf", "D", 15.0, 15.0m });
            dt.Rows.Add(new object[] { "akjsgdf", "C", 293.0, 293.0m });
            dgwResult.DataSource = dt;
        }

private void InitializeComponent()
        {
            this.dgwResult = new System.Windows.Forms.DataGridView();
            this.dgw_1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dgw_2 = new System.Windows.Forms.DataGridViewComboBoxColumn();
            this.dgw_3 = new System.Windows.Forms.DataGridViewComboBoxColumn();
            this.dgw_4 = new System.Windows.Forms.DataGridViewComboBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dgwResult)).BeginInit();
            this.SuspendLayout();
            // 
            // dgwResult
            // 
            this.dgwResult.AllowUserToAddRows = false;
            this.dgwResult.AllowUserToDeleteRows = false;
            this.dgwResult.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            this.dgwResult.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgwResult.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.dgw_1,
            this.dgw_2,
            this.dgw_3,
            this.dgw_4});
            this.dgwResult.Location = new System.Drawing.Point(12, 12);
            this.dgwResult.Name = "dgwResult";
            this.dgwResult.RowHeadersVisible = false;
            this.dgwResult.Size = new System.Drawing.Size(268, 150);
            this.dgwResult.TabIndex = 0;
            this.dgwResult.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgwResult_CellClick);
            // 
            // dgw_1
            // 
            this.dgw_1.DataPropertyName = "one";
            this.dgw_1.HeaderText = "One";
            this.dgw_1.Name = "dgw_1";
            // 
            // dgw_2
            // 
            this.dgw_2.DataPropertyName = "two";
            this.dgw_2.HeaderText = "Two";
            this.dgw_2.Name = "dgw_2";
            // 
            // dgw_3
            // 
            this.dgw_3.DataPropertyName = "three";
            this.dgw_3.HeaderText = "Double";
            this.dgw_3.Name = "dgw_3";
            // 
            // dgw_4
            // 
            this.dgw_4.DataPropertyName = "four";
            this.dgw_4.HeaderText = "Decimal";
            this.dgw_4.Name = "dgw_4";
            this.dgw_4.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.dgw_4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Controls.Add(this.dgwResult);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.dgwResult)).EndInit();
            this.ResumeLayout(false);

        }

        private System.Windows.Forms.DataGridView dgwResult;
        private System.Windows.Forms.DataGridViewTextBoxColumn dgw_1;
        private System.Windows.Forms.DataGridViewComboBoxColumn dgw_2;
        private System.Windows.Forms.DataGridViewComboBoxColumn dgw_3;
        private System.Windows.Forms.DataGridViewComboBoxColumn dgw_4;

Can someone point out why the behavior is so strange for decimal? Maybe I’m missing something simple here?

  • 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-26T20:11:28+00:00Added an answer on May 26, 2026 at 8:11 pm

    The reason you’re getting that ‘strange’ operation is because the decimal numbers are not in the list used to populate the column’s DataSource.

    The problem is fixed by changing the code that populates the DataTable to this:

    dt.Rows.Add(new object[] { "akjsgdf", "A", 10.0, 10m });
    dt.Rows.Add(new object[] { "akjsgdf", "B", 15.0, 15m });
    dt.Rows.Add(new object[] { "akjsgdf", "C", 20.0, 20m });
    dt.Rows.Add(new object[] { "akjsgdf", "D", 15.0, 15m });
    dt.Rows.Add(new object[] { "akjsgdf", "C", 293.0, 293m });
    

    I reckon the DataGridView calls the .ToString() function on each element in the column’s DataSource to find the match. Since 1.0 does not equal 1 (in string terms), no item is selected when you open the drop down menu of the combo box.

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

Sidebar

Related Questions

I have a DataGridView which is bound to a DataTable that contains a column
I have a DataTable which is bound to datagridview (Winforms)... I use the following
I have string column with numbers in a datagridview.It is not bound, I would
I have a datagridview where the users can select which subset of columns to
I have a datagridview which is bound to some data. One of the fields
I have a datagridview bound from a datatable. I have a calculated column linetotal
I have a DataGridView bound to the collection, which is changed frequently (not collection
I have a DataGridView that is bound to a DataTable, is there a way
I have a windows forms DataGridView that contains some DataGridViewComboBoxCell s that are bound
I have a datagridview bound to a bindingsource. Two of the columns contain values

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.