Gday,

Am relatively new to dotnet so excuse me if this seems rather simple.

I am trying to get the value of a bound combo box that has been set
when the form is opened, and use this for another control. I am having
trouble doing this for some reason.

Here is what I am trying to do:

Decimal var1 = (Decimal)cboMyComboBox.SelectedValue;

This appears to return a datarow? Do I need to create a datarow object
then access the value I need that way, or can I just access the
selected item similar to what I am doing above?

Also, the combo box has an id field (value member) and a display field
(display member).

Thanks,

Peter

Re: get value from combo box by Bart

Bart
Thu Feb 02 06:53:15 CST 2006

Hi,

"Peter" <p.strong@gmail.com> wrote in message
news:1138856341.967173.222250@z14g2000cwz.googlegroups.com...
> Gday,
>
> Am relatively new to dotnet so excuse me if this seems rather simple.
>
> I am trying to get the value of a bound combo box that has been set
> when the form is opened, and use this for another control. I am having
> trouble doing this for some reason.
>
> Here is what I am trying to do:
>
> Decimal var1 = (Decimal)cboMyComboBox.SelectedValue;
>
> This appears to return a datarow? Do I need to create a datarow object
> then access the value I need that way, or can I just access the
> selected item similar to what I am doing above?
>
> Also, the combo box has an id field (value member) and a display field
> (display member).

If you have set ValueMember correctly, then SelectedValue should return the
value of the ValueMember-field of the current item/row. There might be a
chance change-events fires before ValueMember has been set, so you could
try:

private void cboMyComboBox_SelectedIndexChanged( .... )
{
if ( cboMyComboBox.ValueMember!="" )
{
Decimal var1 = (Decimal)cboMyComboBox.SelectedValue;
}
}

HTH,
Greetings


>
> Thanks,
>
> Peter
>



Re: get value from combo box by Peter

Peter
Thu Feb 02 18:56:37 CST 2006


Bart Mermuys wrote:

> If you have set ValueMember correctly, then SelectedValue should return the
> value of the ValueMember-field of the current item/row. There might be a
> chance change-events fires before ValueMember has been set, so you could
> try:
>
> private void cboMyComboBox_SelectedIndexChanged( .... )
> {
> if ( cboMyComboBox.ValueMember!="" )
> {
> Decimal var1 = (Decimal)cboMyComboBox.SelectedValue;
> }
> }
>

Yeah - that works. Excellent.

Thanks for that!

Peter