Sorting Bound DataGridView by ComboBoxColumn displayMember  
Author Message
rfiddelke





PostPosted: Windows Forms Data Controls and Databinding, Sorting Bound DataGridView by ComboBoxColumn displayMember Top

I am having a hard time trying to sort a datagridview by a combobox column. Is this possible Where do I start.

Thanks,
Rob


Windows Forms36  
 
 
krejcimar





PostPosted: Windows Forms Data Controls and Databinding, Sorting Bound DataGridView by ComboBoxColumn displayMember Top

I have the same problem. Is there any solution

I've tried IComparer but it doesn't work for bounded DataGridViews, i.e. DataSource property must not be set.

Martin


 
 
rfiddelke





PostPosted: Windows Forms Data Controls and Databinding, Sorting Bound DataGridView by ComboBoxColumn displayMember Top

I have been trying to figure this out for a while now and ran into the same problem with IComparer. I am working around the issue by sorting the data in the fill method of the tableAdapter and not allowing sorting for that column.

Rob


 
 
krejcimar





PostPosted: Windows Forms Data Controls and Databinding, Sorting Bound DataGridView by ComboBoxColumn displayMember Top

The solution was add a new query to the TableAdapter that sorts the data correct way and when it is needed to sort the grid by a combobox values, just change the query. Just to show the idea. there is an example, which is only a small part of the code I had to write but maybe, it gives some idea about the way I found the solution:

private void iODataGridView_OnComboBoxColumnSorting(object sender, ComboBoxColumnSortingEventArgs e)

{

if (e.currentColumn == null)

this.iOTableAdapter.Fill(this.promelcoDataSet.IO);

else if (e.currentColumn.DisplayMember == "Name")

{

if (e.direction == ListSortDirection.Ascending)

this.iOTableAdapter.FillByNameAsc(this.promelcoDataSet.IO);

else if (e.direction == ListSortDirection.Descending)

this.iOTableAdapter.FillByNameDesc(this.promelcoDataSet.IO);

}

}

where FillByNameAsc and FillByNameDesc are added queries to the DataSet. If more columns were based on combobox cell type and were to remain sortable, more queries have to be added to the DataSet. I had also to define custom ComboBoxColumnSortingEventArgs to keep the information about what and how I need to sort.


 
 
Ken Tucker





PostPosted: Windows Forms Data Controls and Databinding, Sorting Bound DataGridView by ComboBoxColumn displayMember Top

Here is a link on how I do it.