How to databind a combo that has it's items entered through the IDE?

  • Thread starter Thread starter PeterZ
  • Start date Start date
P

PeterZ

Hi,

Win Forms question.

Got a comboBox (myComboBox) with it's items set through the collection
editor in the IDE. These are:

No
Yes
Not Applicable

I also have a strongly typed dataSet (myDataSet) with a table (myTable), one
of the columns is called HEROIN_ADDICT, it may contain one of the values: 0,
1 or 2. Where 0 = No, 1 = Yes, 2 = Not Applicable.

I would like to databind the combo to the HEROIN_ADDICT column so the
appropriate item is selected. I tried setting the SelectedValue property of
myComboBox to "myDataSet - myTable.HEROIN_ADDICT" but this doesn't do
anything at runtime.

Can anyone help?

Cheers,
Z
 
PeterZ said:
Hi,

Win Forms question.

Got a comboBox (myComboBox) with it's items set through the collection
editor in the IDE. These are:

No
Yes
Not Applicable

I also have a strongly typed dataSet (myDataSet) with a table (myTable), one
of the columns is called HEROIN_ADDICT, it may contain one of the values: 0,
1 or 2. Where 0 = No, 1 = Yes, 2 = Not Applicable.

I would like to databind the combo to the HEROIN_ADDICT column so the
appropriate item is selected. I tried setting the SelectedValue property of
myComboBox to "myDataSet - myTable.HEROIN_ADDICT" but this doesn't do
anything at runtime.

Can anyone help?

Peter, are you a drug dealer by any chance ;-)?
Try this. Use a datatable with two columns for combobox datasource:
Id, Desc. Where Id is number and Desc is No, Yes, Not applicable.
Set combobox DisplayMember to Desc and ValueMember to Id.
Finally, bind SelectedValue to HEROIN_ADDICT field.
It should work I think.
 
Hi Miha,

No, not a drug dealer, I leave that to the Australian Olympic cycling
team ;-)

On a serious note, is there a way just to databind the selectedIndex
property of the comboBox to the HEROIN_ADDICT column? I really don't
want to create a lookup dataTable in code if I can easily populate the
combo with the collection editor in the IDE.

Cheers
Peter
 
Hi Peter,

Afaik SelectedIndex is not bindable.
Creating a datasource (such as table) is not that hard either :-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

PeterZ said:
Hi Miha,

No, not a drug dealer, I leave that to the Australian Olympic cycling
team ;-)

On a serious note, is there a way just to databind the selectedIndex
property of the comboBox to the HEROIN_ADDICT column? I really don't
want to create a lookup dataTable in code if I can easily populate the
combo with the collection editor in the IDE.

Cheers
Peter


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
Peter, are you a drug dealer by any chance ;-)?
Try this. Use a datatable with two columns for combobox datasource:
Id, Desc. Where Id is number and Desc is No, Yes, Not applicable.
Set combobox DisplayMember to Desc and ValueMember to Id.
Finally, bind SelectedValue to HEROIN_ADDICT field.
It should work I think.
 
Back
Top