Datagridview中的组合框问题 [英] Problem with Combobox in Datagridview

查看:88
本文介绍了Datagridview中的组合框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在datagridview(C#Windows应用程序)中使用Combobox.我正在使用Dataset绑定组合框中的项目.但是当我在第一行中选择第二个项目时,控件会自动转到第二行.就像我只能按与数据集中相同的顺序选择项目.例如

数据集中的项目
abcd
efgh
jhgf

同样在组合框中,我可以按以下相同的顺序进行选择.

abcd
efgh
jhgf

我无法选择

efgh
jhgf
abcd

请给我一些建议以解决此问题..

I am using Combobox in datagridview (C# windows application).I am using Dataset to bind the items in combobox.But when i select the second item in first row,the control goes to the second row automatically.This is like I can only select the items in the same order as in the Dataset.For example

Items in Dataset
abcd
efgh
jhgf

In combobox also,I can choose in the same order as below.

abcd
efgh
jhgf

I am not able to choose as

efgh
jhgf
abcd

Please give me some suggestions to fix this..

推荐答案

这是我的代码..
Here is my code..
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables["ClsIndex"].Rows.Count > 0)
                    {
                        dataGrdBenClassIndex.Columns.Clear();
                        dataGrdBenClassIndex.AutoGenerateColumns = false;
                        dataGrdBenClassIndex.DataSource = ds.Tables[0];

                        DataGridViewTextBoxColumn classColumn = new DataGridViewTextBoxColumn();
                        classColumn.HeaderText = "Class";
                        classColumn.Name = "CLASS";
                        classColumn.Width = 150;
                        classColumn.DataPropertyName = "Class";
                        classColumn.CellTemplate = new DataGridViewTextBoxCell();
                        classColumn.ReadOnly = false;
                        classColumn.ToolTipText = "Double Click this cell to change the class name";
                        classColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        dataGrdBenClassIndex.Columns.Add(classColumn);

                        DataGridViewComboBoxColumn typeColumn = new DataGridViewComboBoxColumn();
                        typeColumn.Name = "TYPE";                        
                        typeColumn.DataPropertyName = "Type";
                        typeColumn.DisplayMember = "Type";
                        typeColumn.DataSource = ds.Tables[0];
                        typeColumn.HeaderText = "Type";                        
                        typeColumn.ValueType = typeof(string);
                        typeColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                        typeColumn.Width = 220;
                        typeColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
                        typeColumn.Sorted = false;
                        typeColumn.ReadOnly = false;
                        typeColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        typeColumn.ToolTipText = "Please select Type";                        
                        dataGrdBenClassIndex.Columns.Add(typeColumn);
}
}


只需清除数据集或Datatabel或

绑定查询以按名称设置顺序. ofr,例如:

从按MastName的MastTabel顺序中选择MastName,MastId.
Just Clear Dataset or Datatabel or

Bind query to set order by Name. ofr eg:

Select MastName,MastId from MastTabel order by MastName.


这篇关于Datagridview中的组合框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆