I have a combobox that list two items. Lets call it cbxCombo. I have
a table extracted from an MS SQL database. This table has a column
that will either be 1 or 2. If the value in the table is 1, the
cbxCombo.SelectedIndex = 0. If the value in the table is 2 the
cbxCombo.SelectedIndex = 1. How do I go about extacting that value
from the column so that I can test it in an if statement.

I'm using C#
Ideally it would look something like this.

if(dataset.datatable.Columns["column"] == 1)
{
cbxCombo.SelectedIndex = 0
}

The data types in the "if" statements are different and I understand
why it doesn't work. Question is how does one make it work.

Re: getting the value of a datacolumn by W

W
Wed Aug 31 15:55:52 CDT 2005

If you specify a DataSource ie cbo.DataSource = ds.Tables[0];

Then specify a DisplayMember and ValueMemeber, you can use SelectedIndex to
get that value.

So you could specify cbo.DisplayMember = "WhateverColumn";
cbo.ValueMember = "WhateverColumn";

Now you can reference whichever you want by using cbo.SelectedValue.
"CyberBless" <groups@cyberbless.com> wrote in message
news:1125517059.123854.228640@g43g2000cwa.googlegroups.com...
>I have a combobox that list two items. Lets call it cbxCombo. I have
> a table extracted from an MS SQL database. This table has a column
> that will either be 1 or 2. If the value in the table is 1, the
> cbxCombo.SelectedIndex = 0. If the value in the table is 2 the
> cbxCombo.SelectedIndex = 1. How do I go about extacting that value
> from the column so that I can test it in an if statement.
>
> I'm using C#
> Ideally it would look something like this.
>
> if(dataset.datatable.Columns["column"] == 1)
> {
> cbxCombo.SelectedIndex = 0
> }
>
> The data types in the "if" statements are different and I understand
> why it doesn't work. Question is how does one make it work.
>