CheckedListBox Question - Item vs Value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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/magazine/columns/qa/default.aspx
 
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
 
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.
 
Send me the ex.tostring (Exception string) and I will be able to tell you.
 
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.errHandler(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.fillOptions(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_Load(Object sender =
{BuddysRoofing.frmMain}, System.EventArgs e = {System.EventArgs}) Line 2099 +
0x37 bytes
<<<
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top