By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

CheckedListBox Question - Item vs Value

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.