Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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..
Posted
Comments
ShotDriller 13-Sep-12 9:40am    
Please Provide Your Code...

Here is my code..
C#
                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);
}
}
 
Share this answer
 
v2
Just Clear Dataset or Datatabel or

Bind query to set order by Name. ofr eg:

Select MastName,MastId from MastTabel order by MastName.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900