Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting DataGridView by Column.DisplayMember
    primarykey
    data
    text
    <p>I have a <code>DataGridView</code> with a few <code>DataGridViewComboBoxColumn</code>'s where the actual value is tied to an ID but the <code>DisplayMember</code> is the string counterpart in a lookup table. I'm trying to make it so when I sort by that column then the sort is done based on the <code>DisplayMember</code>, not the <code>ValueMember</code>. I know this was addressed in <a href="https://stackoverflow.com/q/2895849/371184">this question</a> but the answer was less than in depth nor did I understand it.</p> <p>What I've tried thus far</p> <ul> <li>Binding to the <code>SortCompare</code> event but discovered it isn't fired on a databound column.</li> <li>Manually sorting on the <code>ColumnHeaderMouseClick</code> event but rows in a <code>DataGridViewRowCollection</code> are read-only and I can't programatically insert rows (while swapping) on a databound collection.</li> <li>Creating a hidden <code>DataGridViewTextBoxColumn</code> where the cells are automatically set to the <code>DisplayMember</code> of the original column then attempting to sort that column instead. However, a databound collection cannot be sorted based on an unbounded column.</li> </ul> <p><strong>Edit:</strong> To further clarify: I'm attempting to sort the entire <code>DataGridView</code> based on the <code>DisplayMember</code> of the comboboxes, not sort the comboboxes themselves.</p> <p>How can I sort a <code>DataGridView</code> based on the <code>DisplayMember</code> of a databound <code>DataGridViewComboBoxColumn</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload