On Aug 13, 6:06*pm, Sweetiecakes <x...@x.comwrote:
Yet another newbie question. I have a dataset of an table: I need to
list the values in the Windows Forms application.
A ComboBox, more specifically. The table does not contain any directly
user-readable data: how would I "customize" what the ComboBox's
SelectedText says to a custom format, which could contain data from the
table's fields?
You should bind the DataGridViewComboBoxColumn to a data source (via
its DataSource property), which contains mappings between display
text, and actual values. For example, assuming you have integer values
stored in the database:
Array mapping = new[] {
new { Text = "Red", Value = 1 },
new { Text = "Green", Value = 2 },
new { Text = "Blue", Value = 3 }
} ;
column.DataSource = mapping;
column.DisplayMember = "Text";
column.ValueMember = "Value";
Now the actual value read from or written into the datasource will be
whatever is in the Value property, but the text displayed in the cell
will be taken from the corresponding Text property.