Along with Joel Etherton, answer that an event you can handle will allow you to override the displayed value for the cell.
So, as he said, you will need two columns. One is a strongly typed numeric column with -1s for text values. The other is a hidden text column with real values ββ(mixed numbers and text values). As-it will sort correctly, but the user will see -1s instead of the actual value.
To fix this, we need this code:
Private Sub dgDisplay_CellFormatting(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _ Handles dgDisplay.CellFormatting If Not (e.ColumnIndex = dgDisplay.Columns("NumericColumn").Index _ AndAlso e.RowIndex >= 0) Then Exit Sub Dim newVal As String = dgDisplay.Item("ActualColumn", e.RowIndex).Value e.Value = newVal End Sub
This will show the actual text value you want to see, even if the value in the DataSource is only numeric.
If you intend to filter on a DataView behind you a DataGridView , make sure you filter the hidden column.
source share