473,750 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programatically changing value of databound combobox

I posted this in dotnet.language s.vb.controls but thought I'd post here as
well..
I have a combobox that is bound to a dataview generated from a dataset.

The dataset has a single table (called "Data") with two columns "Id" and
"Descriptio n". Id contains a code and description contains the
description that is displayed in the combobox.

The dataview is generated from the dataset using dv =
ds.Tables("Data ").DefaultV iew.

The Combobox is bound using :

txtLookup.DataS ource = dv
txtLookup.Value Member = "Id"

txtLookup.Displ ayMember = "Descriptio n"

This works fine, I can read the current "Id" from the combobox using the
txtlookup.selec tedvalue property.

However, if I want to programatically set the starting value of the
combobox, I can't seem to work out how to do it. I thought I could just set
the selectedvalue property to any of the vaules of "id" and the combobox
would then display the corresponding description. This appears not to be
the case. I don't know if it is getting confused by the fact that the "Id"
field in the datatable is numeric or if I'm just doing it wrong!

What should I be doing?

Thanks in advance

Simon
Nov 21 '05 #1
7 4565
Combo box index are Zero based and incremental. Your ID column does not have
to correspond with this at all and can be any unique numbers. And yes,
selecting a dropdownlist item is done by setting the SelectedItemInd ex to an
appropriate number.
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I posted this in dotnet.language s.vb.controls but thought I'd post here as
well..
I have a combobox that is bound to a dataview generated from a dataset.

The dataset has a single table (called "Data") with two columns "Id" and
"Descriptio n". Id contains a code and description contains the
description that is displayed in the combobox.

The dataview is generated from the dataset using dv =
ds.Tables("Data ").DefaultV iew.

The Combobox is bound using :

txtLookup.DataS ource = dv
txtLookup.Value Member = "Id"

txtLookup.Displ ayMember = "Descriptio n"

This works fine, I can read the current "Id" from the combobox using the
txtlookup.selec tedvalue property.

However, if I want to programatically set the starting value of the
combobox, I can't seem to work out how to do it. I thought I could just
set the selectedvalue property to any of the vaules of "id" and the
combobox would then display the corresponding description. This appears
not to be the case. I don't know if it is getting confused by the fact
that the "Id" field in the datatable is numeric or if I'm just doing it
wrong!

What should I be doing?

Thanks in advance

Simon

Nov 21 '05 #2
But how do I know what the appropriate no is ???

If my datatable has for example:

Id Description
1 Ford
2 Vauxhall
3 Peugeot
6 Ferrari

and I want to set the combobox to "Ferrari" (ie ID=6).. How do I do this?

I'm trying to do : txtlookup.selec tedvalue="6" but this isn't doing
what I expect!

I presume that the selecteditemind ex property is an offset through the
datatable. Do I have to scan through the datatable counting how far through
the record I want actually is? Will it matter that I've set the combobox
to sort by Description??

Regards
Simon
"Mr Newbie" <he**@now.com > wrote in message
news:OP******** *****@TK2MSFTNG P11.phx.gbl...
Combo box index are Zero based and incremental. Your ID column does not
have to correspond with this at all and can be any unique numbers. And
yes, selecting a dropdownlist item is done by setting the
SelectedItemInd ex to an appropriate number.
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I posted this in dotnet.language s.vb.controls but thought I'd post here as
well..
I have a combobox that is bound to a dataview generated from a dataset.

The dataset has a single table (called "Data") with two columns "Id" and
"Descriptio n". Id contains a code and description contains the
description that is displayed in the combobox.

The dataview is generated from the dataset using dv =
ds.Tables("Data ").DefaultV iew.

The Combobox is bound using :

txtLookup.DataS ource = dv
txtLookup.Value Member = "Id"

txtLookup.Displ ayMember = "Descriptio n"

This works fine, I can read the current "Id" from the combobox using the
txtlookup.selec tedvalue property.

However, if I want to programatically set the starting value of the
combobox, I can't seem to work out how to do it. I thought I could just
set the selectedvalue property to any of the vaules of "id" and the
combobox would then display the corresponding description. This appears
not to be the case. I don't know if it is getting confused by the fact
that the "Id" field in the datatable is numeric or if I'm just doing it
wrong!

What should I be doing?

Thanks in advance

Simon


Nov 21 '05 #3
Hi,

"Simon Verona" <no****@nomail. zzz> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
But how do I know what the appropriate no is ???

If my datatable has for example:

Id Description
1 Ford
2 Vauxhall
3 Peugeot
6 Ferrari

and I want to set the combobox to "Ferrari" (ie ID=6).. How do I do this?

I'm trying to do : txtlookup.selec tedvalue="6" but this isn't doing
what I expect!
You need to know the datatype of the "ValueMembe r" column and if it is by
example an integer and not a string then you would use:

txtlookup.Selec tedValue = 6 ' without quotes
HTH,
Greetings


I presume that the selecteditemind ex property is an offset through the
datatable. Do I have to scan through the datatable counting how far
through the record I want actually is? Will it matter that I've set the
combobox to sort by Description??

Regards
Simon
"Mr Newbie" <he**@now.com > wrote in message
news:OP******** *****@TK2MSFTNG P11.phx.gbl...
Combo box index are Zero based and incremental. Your ID column does not
have to correspond with this at all and can be any unique numbers. And
yes, selecting a dropdownlist item is done by setting the
SelectedItemInd ex to an appropriate number.
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I posted this in dotnet.language s.vb.controls but thought I'd post here
as well..
I have a combobox that is bound to a dataview generated from a dataset.

The dataset has a single table (called "Data") with two columns "Id"
and "Descriptio n". Id contains a code and description contains the
description that is displayed in the combobox.

The dataview is generated from the dataset using dv =
ds.Tables("Data ").DefaultV iew.

The Combobox is bound using :

txtLookup.DataS ource = dv
txtLookup.Value Member = "Id"

txtLookup.Displ ayMember = "Descriptio n"

This works fine, I can read the current "Id" from the combobox using the
txtlookup.selec tedvalue property.

However, if I want to programatically set the starting value of the
combobox, I can't seem to work out how to do it. I thought I could just
set the selectedvalue property to any of the vaules of "id" and the
combobox would then display the corresponding description. This appears
not to be the case. I don't know if it is getting confused by the fact
that the "Id" field in the datatable is numeric or if I'm just doing it
wrong!

What should I be doing?

Thanks in advance

Simon



Nov 21 '05 #4
I must be doing something very wrong because that doesn't help!

Even though the "Id" field contains numerics, it is defined as a string
field.

Regards
Simon
"Bart Mermuys" <bm************ *@hotmail.com> wrote in message
news:eb******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

"Simon Verona" <no****@nomail. zzz> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
But how do I know what the appropriate no is ???

If my datatable has for example:

Id Description
1 Ford
2 Vauxhall
3 Peugeot
6 Ferrari

and I want to set the combobox to "Ferrari" (ie ID=6).. How do I do this?

I'm trying to do : txtlookup.selec tedvalue="6" but this isn't doing
what I expect!


You need to know the datatype of the "ValueMembe r" column and if it is by
example an integer and not a string then you would use:

txtlookup.Selec tedValue = 6 ' without quotes
HTH,
Greetings


I presume that the selecteditemind ex property is an offset through the
datatable. Do I have to scan through the datatable counting how far
through the record I want actually is? Will it matter that I've set the
combobox to sort by Description??

Regards
Simon
"Mr Newbie" <he**@now.com > wrote in message
news:OP******** *****@TK2MSFTNG P11.phx.gbl...
Combo box index are Zero based and incremental. Your ID column does not
have to correspond with this at all and can be any unique numbers. And
yes, selecting a dropdownlist item is done by setting the
SelectedItemInd ex to an appropriate number.
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I posted this in dotnet.language s.vb.controls but thought I'd post here
as well..
I have a combobox that is bound to a dataview generated from a dataset.

The dataset has a single table (called "Data") with two columns "Id"
and "Descriptio n". Id contains a code and description contains the
description that is displayed in the combobox.

The dataview is generated from the dataset using dv =
ds.Tables("Data ").DefaultV iew.

The Combobox is bound using :

txtLookup.DataS ource = dv
txtLookup.Value Member = "Id"

txtLookup.Displ ayMember = "Descriptio n"

This works fine, I can read the current "Id" from the combobox using
the txtlookup.selec tedvalue property.

However, if I want to programatically set the starting value of the
combobox, I can't seem to work out how to do it. I thought I could
just set the selectedvalue property to any of the vaules of "id" and
the combobox would then display the corresponding description. This
appears not to be the case. I don't know if it is getting confused by
the fact that the "Id" field in the datatable is numeric or if I'm just
doing it wrong!

What should I be doing?

Thanks in advance

Simon



Nov 21 '05 #5
OK,

'For example, a delete operation

datasetMyVehicl es.CarsTable.Ro ws.Find(
CarValueFromCom boBoxInThisCase ItIs_6 ).Delete()

myDataAdapter.U pdate( datasetMyVehicl es.CarsTable )
HTH
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
I must be doing something very wrong because that doesn't help!

Even though the "Id" field contains numerics, it is defined as a string
field.

Regards
Simon
"Bart Mermuys" <bm************ *@hotmail.com> wrote in message
news:eb******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

"Simon Verona" <no****@nomail. zzz> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
But how do I know what the appropriate no is ???

If my datatable has for example:

Id Description
1 Ford
2 Vauxhall
3 Peugeot
6 Ferrari

and I want to set the combobox to "Ferrari" (ie ID=6).. How do I do
this?

I'm trying to do : txtlookup.selec tedvalue="6" but this isn't
doing what I expect!


You need to know the datatype of the "ValueMembe r" column and if it is by
example an integer and not a string then you would use:

txtlookup.Selec tedValue = 6 ' without quotes
HTH,
Greetings


I presume that the selecteditemind ex property is an offset through the
datatable. Do I have to scan through the datatable counting how far
through the record I want actually is? Will it matter that I've set
the combobox to sort by Description??

Regards
Simon
"Mr Newbie" <he**@now.com > wrote in message
news:OP******** *****@TK2MSFTNG P11.phx.gbl...
Combo box index are Zero based and incremental. Your ID column does not
have to correspond with this at all and can be any unique numbers. And
yes, selecting a dropdownlist item is done by setting the
SelectedItemInd ex to an appropriate number.
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
>I posted this in dotnet.language s.vb.controls but thought I'd post here
>as well..
>
>
> I have a combobox that is bound to a dataview generated from a
> dataset.
>
> The dataset has a single table (called "Data") with two columns "Id"
> and "Descriptio n". Id contains a code and description contains the
> description that is displayed in the combobox.
>
> The dataview is generated from the dataset using dv =
> ds.Tables("Data ").DefaultV iew.
>
> The Combobox is bound using :
>
> txtLookup.DataS ource = dv
> txtLookup.Value Member = "Id"
>
> txtLookup.Displ ayMember = "Descriptio n"
>
>
>
> This works fine, I can read the current "Id" from the combobox using
> the txtlookup.selec tedvalue property.
>
> However, if I want to programatically set the starting value of the
> combobox, I can't seem to work out how to do it. I thought I could
> just set the selectedvalue property to any of the vaules of "id" and
> the combobox would then display the corresponding description. This
> appears not to be the case. I don't know if it is getting confused by
> the fact that the "Id" field in the datatable is numeric or if I'm
> just doing it wrong!
>
> What should I be doing?
>
>
>
> Thanks in advance
>
> Simon
>
>



Nov 21 '05 #6
Hi,

"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
I must be doing something very wrong because that doesn't help!

Even though the "Id" field contains numerics, it is defined as a string
field.
It would be strange that a numeric field would have a string datatype but it
shouldn't matter for the ComboBox, as long as you use the same type with
SelectedValue.

Check the column type (to be sure):
DataTable.Colum ns("id").DataTy pe.ToString()

The ComboBox is visible and you are setting SelectedValue after the ComboBox
is bound, right ?
greetings

Regards
Simon
"Bart Mermuys" <bm************ *@hotmail.com> wrote in message
news:eb******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

"Simon Verona" <no****@nomail. zzz> wrote in message
news:uG******** ******@TK2MSFTN GP15.phx.gbl...
But how do I know what the appropriate no is ???

If my datatable has for example:

Id Description
1 Ford
2 Vauxhall
3 Peugeot
6 Ferrari

and I want to set the combobox to "Ferrari" (ie ID=6).. How do I do
this?

I'm trying to do : txtlookup.selec tedvalue="6" but this isn't
doing what I expect!


You need to know the datatype of the "ValueMembe r" column and if it is by
example an integer and not a string then you would use:

txtlookup.Selec tedValue = 6 ' without quotes
HTH,
Greetings


I presume that the selecteditemind ex property is an offset through the
datatable. Do I have to scan through the datatable counting how far
through the record I want actually is? Will it matter that I've set
the combobox to sort by Description??

Regards
Simon
"Mr Newbie" <he**@now.com > wrote in message
news:OP******** *****@TK2MSFTNG P11.phx.gbl...
Combo box index are Zero based and incremental. Your ID column does not
have to correspond with this at all and can be any unique numbers. And
yes, selecting a dropdownlist item is done by setting the
SelectedItemInd ex to an appropriate number.
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
>I posted this in dotnet.language s.vb.controls but thought I'd post here
>as well..
>
>
> I have a combobox that is bound to a dataview generated from a
> dataset.
>
> The dataset has a single table (called "Data") with two columns "Id"
> and "Descriptio n". Id contains a code and description contains the
> description that is displayed in the combobox.
>
> The dataview is generated from the dataset using dv =
> ds.Tables("Data ").DefaultV iew.
>
> The Combobox is bound using :
>
> txtLookup.DataS ource = dv
> txtLookup.Value Member = "Id"
>
> txtLookup.Displ ayMember = "Descriptio n"
>
>
>
> This works fine, I can read the current "Id" from the combobox using
> the txtlookup.selec tedvalue property.
>
> However, if I want to programatically set the starting value of the
> combobox, I can't seem to work out how to do it. I thought I could
> just set the selectedvalue property to any of the vaules of "id" and
> the combobox would then display the corresponding description. This
> appears not to be the case. I don't know if it is getting confused by
> the fact that the "Id" field in the datatable is numeric or if I'm
> just doing it wrong!
>
> What should I be doing?
>
>
>
> Thanks in advance
>
> Simon
>
>



Nov 21 '05 #7
Just to complete this thread, there was nothing actually wrong with the code
I had, the selectvalue works just fine. My problem was actually completely
unrelated to the combobox but was a corruption of the value that I was
setting the selectedvalue to!

Sometimes yuo just don't see the wood for the trees!!

Thanks

Regards
Simon
"Simon Verona" <no****@nomail. zzz> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
I posted this in dotnet.language s.vb.controls but thought I'd post here as
well..
I have a combobox that is bound to a dataview generated from a dataset.

The dataset has a single table (called "Data") with two columns "Id" and
"Descriptio n". Id contains a code and description contains the
description that is displayed in the combobox.

The dataview is generated from the dataset using dv =
ds.Tables("Data ").DefaultV iew.

The Combobox is bound using :

txtLookup.DataS ource = dv
txtLookup.Value Member = "Id"

txtLookup.Displ ayMember = "Descriptio n"

This works fine, I can read the current "Id" from the combobox using the
txtlookup.selec tedvalue property.

However, if I want to programatically set the starting value of the
combobox, I can't seem to work out how to do it. I thought I could just
set the selectedvalue property to any of the vaules of "id" and the
combobox would then display the corresponding description. This appears
not to be the case. I don't know if it is getting confused by the fact
that the "Id" field in the datatable is numeric or if I'm just doing it
wrong!

What should I be doing?

Thanks in advance

Simon

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1131
by: John Smith | last post by:
Hello all: Another day another problem :). How do you synch a databound combobox with the rest of the controls that are on a form. I have a combobox that lists a bunch of names and upon selection I would like the rest of the form items (mostly textboxes) to fill in with the details of the selected name. I have databound the other controls but they do not update, they remain on the first item in the DataSet. I have even tried to use...
1
2062
by: Prem S | last post by:
Hi All I have a databound ComboBox control which is put into the second page of a tab control. When the form loads up, I databind the combo control and populate the control. When I go to change the tab page to the second page, the application hangs...becoming completely non-responsive. If I populate the combo control with no databinding, I can change to
6
2883
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
3
4696
by: Benny | last post by:
Does anyone know how I would go about adding a blank value to the list of items in a ComboBox that has a set datasource? Thank in advance!
3
3684
by: greeknl via AccessMonster.com | last post by:
Is possible to save to a variable in VBA the value a combobox had before it was updated in order to use it because the update value can be retrieved easily Thank you -- Message posted via http://www.accessmonster.com
4
2040
daffurankan
by: daffurankan | last post by:
Hai, this ankan here by this kindly tell me that how can i save a value in combobox which is type in its text field . on visual basic 6.0 act soon asap it is very important for me reply me asap
8
3970
by: lttan123 | last post by:
hi there i am having some difficulties to bind value to combobox in windows application. combo.Items.Add(new List("a","b")) I have created a class. The value is there but what is displayed is the class name. How should i display a value from he value i have keyed in. For instance i want to display 'a'
1
2127
by: Joel1334 | last post by:
Hi! How can I change forecolor of a selected value in combobox? when I select a value in a combobox and press a button to "activate" what I've selected I want the text to be green and then black when I select another value.
0
1002
by: wasim jack | last post by:
sir,I want to change value of combobox of datagridview on the basis of previous combobox value of the same raw of same datagridview
0
8836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9394
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.