English 中文(简体)
C# DataGridView Decimal ComboBox
原标题:C# DataGridView Decimal ComboBox column

我有一个数据网格,有一个装束子,含有精度值。 用户可以选择其中一种有效术语。 然而,我面临一个奇怪的问题——当你在选定的价值中点击 com器,把一些how光树脂放在名单上的第一.上,从而失去了已经选定的树脂。 看一看情况

这是对窗口的初步看法:

“entergraph

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

这正是我选择一个具有贬值价值的栏目。 甄选(第293号)缺失

enter image description here

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;

难道有人可以指出,为什么行为如此奇怪? Maybe 在这里,我没有简单的东西?

最佳回答

你之所以重新认识到,奇怪的是,数字不是用于填满栏。

这个问题通过修改法典确定:

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 elements in the栏DataSource to establish the same. 由于1.0>并不等于1(按指示数计算),在你打开 com球箱时,没有选定任何项目。

问题回答

暂无回答




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签