473,761 Members | 7,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CheckedListBox Question - Item vs Value

Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron
Nov 21 '05 #1
9 8499
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #2
I'm having an issue with the dataset. Can you see what I'm doing wrong?

Here is my code in the form.
I have a SQL Class returning a dataset.

Dim ds As DataSet
ds = objSQL.getDataS et(strOptionFil l)
clbFill.DataSou rce = ds
clbFill.Display Member = "OptionText "
clbFill.ValueMe mber = "OptionID"
clbFill.Refresh ()
ds.Dispose()

Here is the function in the SQL Class
Public Function getDataSet(ByVa l strSQL As String) As DataSet
Dim ds As New DataSet
Dim da As New SqlDataAdapter( strSQL, dbConn)
Try
da.Fill(ds)
Catch ex As Exception
RaiseEvent ErrRaised(ex.So urce, ex.Message)
End Try
da.Dispose()
End Function

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #3
I'm having an issue with the dataset. Can you see what I'm doing wrong?

Here is my code in the form.
I have a SQL Class returning a dataset.

Dim ds As DataSet
ds = objSQL.getDataS et(strOptionFil l)
clbFill.DataSou rce = ds
clbFill.Display Member = "OptionText "
clbFill.ValueMe mber = "OptionID"
clbFill.Refresh ()
ds.Dispose()

Here is the function in the SQL Class
Public Function getDataSet(ByVa l strSQL As String) As DataSet
Dim ds As New DataSet
Dim da As New SqlDataAdapter( strSQL, dbConn)
Try
da.Fill(ds)
Catch ex As Exception
RaiseEvent ErrRaised(ex.So urce, ex.Message)
End Try
da.Dispose()
End Function

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #4
As an addendum to my other post. I did adjust the code to add the SQL Command.
It's the DA.FILL(DS) that is crashing.

I'm not sure why.

Ron.

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #5
As an addendum to my other post. I did adjust the code to add the SQL Command.
It's the DA.FILL(DS) that is crashing.

I'm not sure why.

Ron.

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #6
Send me the ex.tostring (Exception string) and I will be able to tell you.

"Capt_Ron" wrote:
As an addendum to my other post. I did adjust the code to add the SQL Command.
It's the DA.FILL(DS) that is crashing.

I'm not sure why.

Ron.

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #7
Send me the ex.tostring (Exception string) and I will be able to tell you.

"Capt_Ron" wrote:
As an addendum to my other post. I did adjust the code to add the SQL Command.
It's the DA.FILL(DS) that is crashing.

I'm not sure why.

Ron.

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:
Hello,
I would like to set the value of the item in the checked list box.
I have a datareader that has 2 columns. PK and TEXT
I want the TEXT as the Item and the PK as the Value.

I can not find anywhere that I can SET the value. But I can GET the
SELECTED ITEM VALUE.

Any direction would be helpfull.

Thank you for your time.
Ron

Nov 21 '05 #8
Is this what you are looking for? This is actually what the call stack
shows. The ex.tostring goes to a message box.
Ron.
BuddysRoofing.e xe!BuddysRoofin g.MainModule.er rHandler(String strSender =
"System.Dat a", String strException = "System.Argumen tNullException: Value
cannot be null.
Parameter name: dataSet
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, String srcTable)
at sqlClass.SQLObj .getDataSet(Str ing strSQL, String strTable) in
C:\Documents and Settings\User\M y Documents\Visua l Studio Projects\ASP NET
II\sqlClass\SQL Obj.vb:line 79") Line 73 Basic
sqlclass.dll!sq lClass.SQLObj.g etDataSet(Strin g strSQL = "SELECT OptionID,
OptionText FROM tblOptions WHERE OptionType='Shi ngle' AND Active = 1", String
strTable = "tblOptions ") Line 81 + 0x35 bytes Basic

BuddysRoofing.e xe!BuddysRoofin g.frmMain.fillO ptions(System.W indows.Forms.Ch eckedListBox
clbFill = {System.Windows .Forms.CheckedL istBox}, String strOptionFill =
"SELECT OptionID, OptionText FROM tblOptions WHERE OptionType='Shi ngle' AND
Active = 1", String strTable = "tblOptions ") Line 2122 + 0x17 bytes Basic
BuddysRoofing.e xe!BuddysRoofin g.frmMain.frmMa in_Load(Object sender =
{BuddysRoofing. frmMain}, System.EventArg s e = {System.EventAr gs}) Line 2099 +
0x37 bytes
<<<

"Le MasterChief" wrote:
Send me the ex.tostring (Exception string) and I will be able to tell you.

"Capt_Ron" wrote:
As an addendum to my other post. I did adjust the code to add the SQL Command.
It's the DA.FILL(DS) that is crashing.

I'm not sure why.

Ron.

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:

> Hello,
> I would like to set the value of the item in the checked list box.
> I have a datareader that has 2 columns. PK and TEXT
> I want the TEXT as the Item and the PK as the Value.
>
> I can not find anywhere that I can SET the value. But I can GET the
> SELECTED ITEM VALUE.
>
> Any direction would be helpfull.
>
> Thank you for your time.
> Ron

Nov 21 '05 #9
Is this what you are looking for? This is actually what the call stack
shows. The ex.tostring goes to a message box.
Ron.
BuddysRoofing.e xe!BuddysRoofin g.MainModule.er rHandler(String strSender =
"System.Dat a", String strException = "System.Argumen tNullException: Value
cannot be null.
Parameter name: dataSet
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, String srcTable)
at sqlClass.SQLObj .getDataSet(Str ing strSQL, String strTable) in
C:\Documents and Settings\User\M y Documents\Visua l Studio Projects\ASP NET
II\sqlClass\SQL Obj.vb:line 79") Line 73 Basic
sqlclass.dll!sq lClass.SQLObj.g etDataSet(Strin g strSQL = "SELECT OptionID,
OptionText FROM tblOptions WHERE OptionType='Shi ngle' AND Active = 1", String
strTable = "tblOptions ") Line 81 + 0x35 bytes Basic

BuddysRoofing.e xe!BuddysRoofin g.frmMain.fillO ptions(System.W indows.Forms.Ch eckedListBox
clbFill = {System.Windows .Forms.CheckedL istBox}, String strOptionFill =
"SELECT OptionID, OptionText FROM tblOptions WHERE OptionType='Shi ngle' AND
Active = 1", String strTable = "tblOptions ") Line 2122 + 0x17 bytes Basic
BuddysRoofing.e xe!BuddysRoofin g.frmMain.frmMa in_Load(Object sender =
{BuddysRoofing. frmMain}, System.EventArg s e = {System.EventAr gs}) Line 2099 +
0x37 bytes
<<<

"Le MasterChief" wrote:
Send me the ex.tostring (Exception string) and I will be able to tell you.

"Capt_Ron" wrote:
As an addendum to my other post. I did adjust the code to add the SQL Command.
It's the DA.FILL(DS) that is crashing.

I'm not sure why.

Ron.

"Le MasterChief" wrote:
The quickest way to set the value is to use a dataset for the controls
datasource,and set the controls displaymember=" TEXT" and valuemember="FK ".

Like so:
mylist.datasour ce=GetDatasetFr omDB()
mylist.displaym ember = "TEXT"
mylist.valuemem ber = "FK"
mylist.refresh

If not, you define your own collection class, add the items to it, and then
set the datasource.

If you do not want to use the datasource at all, then you follow the
instructions from this article to create a custom list.

http://www.ftponline.com/vsm/2003_12...a/default.aspx

"Capt_Ron" wrote:

> Hello,
> I would like to set the value of the item in the checked list box.
> I have a datareader that has 2 columns. PK and TEXT
> I want the TEXT as the Item and the PK as the Value.
>
> I can not find anywhere that I can SET the value. But I can GET the
> SELECTED ITEM VALUE.
>
> Any direction would be helpfull.
>
> Thank you for your time.
> Ron

Nov 21 '05 #10

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

Similar topics

4
29101
by: Ram | last post by:
Dear Helpers, I assigened values to checkedlistbox control in the following way cList.DataSource=oDs.Tables.DefaultView; cList.DisplayMember=oDs.Tables.Columns.ToString(); cList.ValueMember=oDs.Tables.Columns.ToString(); where oDs is DataSet
4
3737
by: Reza | last post by:
Hi, I want to check one of the memebrs of a checkedListbox based on its value. I 'm getting a number(say 1355) from another control and based on that number I want to check an item which its value is 1355,how can I do that? thannks.
1
6014
by: xiuyu_0129 | last post by:
Hi All, How do I store a string value for an item in a CheckedListBox in Windows Form? For a web based application, CheckBoxList allowed us to store 2 string values for the item in it. How do I achieve that when making use of the CheckedListBox in windows form. Thanks.
4
3797
by: Matthew | last post by:
Hi, I am using a checkedlistbox on a windows form and binding it to a collection of classes. clbAliases is the checkedlistbox control selectedplace is a class with property placealiases.This property is a collection of placealias classes. Hopefully the rest is self-explanatory..
8
1803
by: Derek Martin | last post by:
Here is some code that I need help with please: Dim result As New ArrayList Try For i = 0 To objecttest1.PersonList.person_returnnumber - 1 result = objecttest1.PersonList.time_returnpunches(objecttest1.PersonList.person_getb yid(i).userid, "03/08/2004", "03/09/2004", True, False) 'The above line returns an object with several proerties, namely, a punch id that I want to be able to get out of the checkedlistbox collection:
2
2308
by: Manuel Canas | last post by:
Hi there, I'm having this dilema with a checkedlistbox. I have an array of items in there, what I want to accomplish is the following; The user could check all the items in the checkedlistbox, but always have at list one item always checked. so if the user has the last item checked and he/she wants to uncheck it, the item should reset it self to a checked state
5
6866
by: mabond | last post by:
Hi Can't believe I've not been able to find the answer to this in the on-line help. I have a CheckedListBox which, via a timer control, is populated with the names of files in a network folder. The "check mark" for each item in the control is determined by the boolean value of a custom property field of the file. That value is found using microsoft's dsofile.dll class.
2
2112
by: bh | last post by:
In the Listbox, there are properties for DisplayMember and ValueMember, just like the combobox, however, those properties are not present for the CheckedListBox. Does this mean that the only value you can actually reference in a CheckedListBox is what is actually dispalyed in the item? Is there a way to list several states (Alabama, Florida, California...) and retreive the value, somehow (AL, FL, CA...) for database lookup, using a...
6
4186
by: painkiller | last post by:
language: vb.net environment: windows forms .net : v1.1 i am having a checkedlistbox control that display document category such as text, image, video, audio etc. these values are coming from database. when a user clicks any of the above values and saves the form, the item's "value" is getting saved in database. and when a user logs back in, his/her previously checked value items should be shown as checked. Everything is working fine...
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9948
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...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7327
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
6603
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
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
2738
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.