471,348 Members | 1,250 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

DataSets: processing data

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?

Thanks
Aug 13 '08 #1
4 1327
Sorry, by "SelectedText" I meant DisplayMember.

Sweetiecakes wrote:
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?

Thanks
Aug 13 '08 #2
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.
Aug 13 '08 #3
Hi. The dataset was filled with an SQLDataAdapter. From what I can see,
this is not possible to do in this case.

Pavel Minaev wrote:
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.
Aug 13 '08 #4
On Aug 13, 6:38*pm, Sweetiecakes <x...@x.comwrote:
Hi. The dataset was filled with an SQLDataAdapter. From what I can see,
this is not possible to do in this case.
It doesn't matter where the dataset was filled from (and indeed,
whether the data source is even a dataset). Note that I'm talking
about binding the _combobox column_ to an array, not binding the
entire DataGridView to something. You can very well do both things at
the same time.
Aug 14 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by sql_er | last post: by
1 post views Thread by Mark Baldwin | last post: by
9 posts views Thread by gardnern | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.