473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Set ComboBox SelectedValue

Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I
know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
Nov 20 '05 #1
6 40874
it should work. may be u can post some more code over here. what is the
style of cbolevel?

Rajesh Patel

"Mike Caputo" <mi************@radarwire.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I
know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.

Nov 20 '05 #2
"Rajesh Patel" <rd****@hotmail.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
it should work. may be u can post some more code over here. what is the
style of cbolevel?

Rajesh Patel
The style of cboLevel is DropDown. It's filled with business objects that
contain an ID field and a Description field. ID is the ValueMember and
Description is the DisplayMember. In this case, ID goes from 1 to 4, and I
am attempting to set the SelectedValue to 4.

cboLevel.SelectedValue = 4

Hmmmmm.... I just thought of something, not sure if this would affect the
ComboBox, but the ID field in the business object I'm using is ReadOnly. I
don't see why this would have any effect, but maybe that is the problem.
Any ideas?

Mike


"Mike Caputo" <mi************@radarwire.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.


Nov 20 '05 #3
Hello Mike
No, you can't do it that way.

Use the Description to set the level you want:
Me.cmbAccountUse.SelectedIndex =
Me.cmbAccountUse.FindString(MyUse.Item(Me._Account UsesDataServices.enmAccoun
tUsesDataServices.Title))
In the code above, the cmbAccountUse combo is tied to the MyUse dataTable

The Item value is the Title of the use
The SelectedValue is the UseType Index

Use a FindString method to get the proper index of the SelectedValue you
desire.

"Mike Caputo" <mi************@radarwire.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I
know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.

Nov 20 '05 #4
Thanks a lot, I think that'll work!

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.

"IbrahimMalluf" <Ib*****@malluf.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
Hello Mike
No, you can't do it that way.

Use the Description to set the level you want:
Me.cmbAccountUse.SelectedIndex =
Me.cmbAccountUse.FindString(MyUse.Item(Me._Account UsesDataServices.enmAccoun tUsesDataServices.Title))
In the code above, the cmbAccountUse combo is tied to the MyUse dataTable

The Item value is the Title of the use
The SelectedValue is the UseType Index

Use a FindString method to get the proper index of the SelectedValue you
desire.

"Mike Caputo" <mi************@radarwire.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.


Nov 20 '05 #5
Actually, I really do need to be able to do it with the value. According to
this article:

http://msdn.microsoft.com/library/de...valuetopic.asp

the SelectedValue can be set in an ASP.NET ListControl, so why in the world
would that not be possible on Windows Forms?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.

"IbrahimMalluf" <Ib*****@malluf.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
Hello Mike
No, you can't do it that way.

Use the Description to set the level you want:
Me.cmbAccountUse.SelectedIndex =
Me.cmbAccountUse.FindString(MyUse.Item(Me._Account UsesDataServices.enmAccoun tUsesDataServices.Title))
In the code above, the cmbAccountUse combo is tied to the MyUse dataTable

The Item value is the Title of the use
The SelectedValue is the UseType Index

Use a FindString method to get the proper index of the SelectedValue you
desire.

"Mike Caputo" <mi************@radarwire.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
Shouldn't I be able to set the selected item of a combobox with the
SelectedValue property? The ComboBox has four items, the values are 1
through 4. Here's an example of what I'm trying to do:

Sub SetLevel(Level as Short)
cboLevel.SelectedValue = Level
End Sub

I try this assignment, and the SelectedValue property remains Nothing. I know for sure that the Level variable is within the 1 - 4 range, and no
exception is thrown anyway. Anyone have any idea why this is?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.


Nov 20 '05 #6
Hi, Mike,
I surfed to the URL you provided and I see that this
class member is valid only for the .NET Framework 1.1 and
above. I have been using .NET 1.0 and have been
experiencing the same problems and frustrations with
this .SelectedValue property as you have. Unless I am
willing to upgrade to VB.NET 1.1 (which I am not in a
position to do, right now), I have to do this:

myObject = Ctype(cboWithStuffInIt.Items
(cboWithStuffInIt.SelectedIndex), myObjectType)

myProperty = myObject.PublicProperty

It's clumsy, but it works. I've read that DirectCast
can be used in lieu of Ctype, but I haven't tried it.

Regards,

Matt Seltzer
Sr. Database Analyst
NYU SoM Child Study Center
New York, NY 10016

-----Original Message-----
Actually, I really do need to be able to do it with the value. According tothis article:

http://msdn.microsoft.com/library/default.asp? url=/library/en-
us/cpref/html/frlrfsystemwebuiwebcontrolslistcontrolclassse
lectedvaluetopic.asp
the SelectedValue can be set in an ASP.NET ListControl, so why in the worldwould that not be possible on Windows Forms?

Mike

--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.

"IbrahimMalluf" <Ib*****@malluf.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
Hello Mike
No, you can't do it that way.

Use the Description to set the level you want:
Me.cmbAccountUse.SelectedIndex =
Me.cmbAccountUse.FindString(MyUse.Item

(Me._AccountUsesDataServices.enmAccoun
tUsesDataServices.Title))
In the code above, the cmbAccountUse combo is tied to the MyUse dataTable

The Item value is the Title of the use
The SelectedValue is the UseType Index

Use a FindString method to get the proper index of the SelectedValue you desire.

"Mike Caputo" <mi************@radarwire.com> wrote in message news:OZ**************@TK2MSFTNGP09.phx.gbl...
> Shouldn't I be able to set the selected item of a combobox with the > SelectedValue property? The ComboBox has four items, the values are 1 > through 4. Here's an example of what I'm trying to do: >
> Sub SetLevel(Level as Short)
> cboLevel.SelectedValue = Level
> End Sub
>
> I try this assignment, and the SelectedValue property remains Nothing.I > know for sure that the Level variable is within the

1 - 4 range, and no > exception is thrown anyway. Anyone have any idea why this is? >
> Mike
>
> --
>
>
> Michael Caputo
> Programmer/Database Administrator
> Simon Economic Systems Ltd.
>
>


.

Nov 20 '05 #7

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

Similar topics

8
by: Supa Hoopsa | last post by:
I have a databound combobox within a datagrid. I have set the DisplayMember and ValueMember. BUT, how do I capture the Value (SelectedValue) when the user changes the selection?
2
by: amber | last post by:
Hello, I have a combobox populated by a dataset filled with data from a SQL view. In the view I have combined two fields to create one. I can't set my combobox.selectedvalue to this value. Any...
1
by: chen qi | last post by:
## i have a table like this: myID myName ------------------------ ----------------------------- 1 aaa 2 bbb 3 ...
0
by: Gary Boulter | last post by:
hi, I have an object populated from the database, The object has three properties, the ID, a description, and a State If I bind the object as a collection to a combo comboBox.DataSourse =...
2
by: Jac | last post by:
Hey, How can I set the display value of a combobox empty? But all the posible choices are available when I push the trianglebut. Sometimes if I set the selecteditem = null it works, other...
0
by: Nick | last post by:
Hi people, There seems to be a peculiar problem that I just encountered. There is a combobox that has a datatable as a datasource with 2 different columns bound to Display and value members....
1
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I generally work on web apps, but I am dealing with a Winform right now and may be missing something really basic. I have a combobox and I would like to know what value has been selected....
11
Frinavale
by: Frinavale | last post by:
This question is going to sound a little crazy but.........How do you set the selected item in a ComboBox? I am populating a ComboBox with a bunch of instances of a custom private class: For...
1
by: sanndeb | last post by:
I have a combobox like <ComboBox Height="23" HorizontalAlignment="Left" Margin="88,13,0,0" Name="cmbYears" VerticalAlignment="Top" Width="112" SelectionChanged="cmbYears_SelectionChanged"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.