473,473 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Create 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 8480
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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.getDataSet(strOptionFill)
clbFill.DataSource = ds
clbFill.DisplayMember = "OptionText"
clbFill.ValueMember = "OptionID"
clbFill.Refresh()
ds.Dispose()

Here is the function in the SQL Class
Public Function getDataSet(ByVal 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.Source, 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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.getDataSet(strOptionFill)
clbFill.DataSource = ds
clbFill.DisplayMember = "OptionText"
clbFill.ValueMember = "OptionID"
clbFill.Refresh()
ds.Dispose()

Here is the function in the SQL Class
Public Function getDataSet(ByVal 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.Source, 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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.exe!BuddysRoofing.MainModule.errHand ler(String strSender =
"System.Data", String strException = "System.ArgumentNullException: Value
cannot be null.
Parameter name: dataSet
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at sqlClass.SQLObj.getDataSet(String strSQL, String strTable) in
C:\Documents and Settings\User\My Documents\Visual Studio Projects\ASP NET
II\sqlClass\SQLObj.vb:line 79") Line 73 Basic
sqlclass.dll!sqlClass.SQLObj.getDataSet(String strSQL = "SELECT OptionID,
OptionText FROM tblOptions WHERE OptionType='Shingle' AND Active = 1", String
strTable = "tblOptions") Line 81 + 0x35 bytes Basic

BuddysRoofing.exe!BuddysRoofing.frmMain.fillOption s(System.Windows.Forms.CheckedListBox
clbFill = {System.Windows.Forms.CheckedListBox}, String strOptionFill =
"SELECT OptionID, OptionText FROM tblOptions WHERE OptionType='Shingle' AND
Active = 1", String strTable = "tblOptions") Line 2122 + 0x17 bytes Basic
BuddysRoofing.exe!BuddysRoofing.frmMain.frmMain_Lo ad(Object sender =
{BuddysRoofing.frmMain}, System.EventArgs e = {System.EventArgs}) 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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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.exe!BuddysRoofing.MainModule.errHand ler(String strSender =
"System.Data", String strException = "System.ArgumentNullException: Value
cannot be null.
Parameter name: dataSet
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at sqlClass.SQLObj.getDataSet(String strSQL, String strTable) in
C:\Documents and Settings\User\My Documents\Visual Studio Projects\ASP NET
II\sqlClass\SQLObj.vb:line 79") Line 73 Basic
sqlclass.dll!sqlClass.SQLObj.getDataSet(String strSQL = "SELECT OptionID,
OptionText FROM tblOptions WHERE OptionType='Shingle' AND Active = 1", String
strTable = "tblOptions") Line 81 + 0x35 bytes Basic

BuddysRoofing.exe!BuddysRoofing.frmMain.fillOption s(System.Windows.Forms.CheckedListBox
clbFill = {System.Windows.Forms.CheckedListBox}, String strOptionFill =
"SELECT OptionID, OptionText FROM tblOptions WHERE OptionType='Shingle' AND
Active = 1", String strTable = "tblOptions") Line 2122 + 0x17 bytes Basic
BuddysRoofing.exe!BuddysRoofing.frmMain.frmMain_Lo ad(Object sender =
{BuddysRoofing.frmMain}, System.EventArgs e = {System.EventArgs}) 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.datasource=GetDatasetFromDB()
mylist.displaymember = "TEXT"
mylist.valuemember = "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
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();...
4
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...
1
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...
4
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...
8
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 =...
2
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...
5
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...
2
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...
6
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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 ...

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.