Question

I have a Datagridview that is bound to a DataTable.

I have added DataGridViewComboBoxColumn to the Datagridview that is has a data property relating to an existing column in the bound DataTable.

Everything works as expected, apart from the fact that at run time, the user is able to re-order every column barring the DataGridViewComboBoxColumn.

Here is the code for implementing the added Column :-

DataGridViewComboBoxColumn TaskEntryCombo = new DataGridViewComboBoxColumn();
            TaskEntryCombo.HeaderText = "Report Name";
            TaskEntryCombo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            TaskEntryCombo.DataSource = ReportTable;
            TaskEntryCombo.DataPropertyName = "TaskName";
            TaskEntryCombo.DisplayMember = "ReportName";
            TaskEntryCombo.ValueMember = "ReportName";
            TaskEntryCombo.MaxDropDownItems = 35;

dgvTemplate.Columns.Add(TaskEntryCombo);

Any Ideas on whatI need to set to allow this? The User is not able to access the column Header for this particular colum and re-order the grid based on the values in the column.

Was it helpful?

Solution

Try this :

TaskEntryCombo.SortMode = DataGridViewColumnSortMode.Automatic

Automatic : The user can sort the column by clicking the column header unless the column headers are used for selection. A sorting glyph will be displayed automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top