CheckedListBox - Get the value of checked items

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

Guest

Dear Helpers,

I assigened values to checkedlistbox control in the following way

cList.DataSource=oDs.Tables[bTableNo].DefaultView;
cList.DisplayMember=oDs.Tables[bTableNo].Columns[1].ToString();
cList.ValueMember=oDs.Tables[bTableNo].Columns[0].ToString();

where oDs is DataSet

the purpose is to display the batchname and allow the user to select multiple batches. To identify the user selection i assigned the BatchID to Value Member.

Once the user makes his selection i want to get the selected batch id. I am able to get the display name by verifying if the item is checked or not. But i dont want the display name. I want to get the IDs associated to that names. I tried using CheckedIndex collection with out any success.

Please advice. I am new to C#

Thanks & Regards
 
To get the index value of the selected item, read the value of the
SelectedIndex property

Ollie

Ram said:
Dear Helpers,

I assigened values to checkedlistbox control in the following way

cList.DataSource=oDs.Tables[bTableNo].DefaultView;
cList.DisplayMember=oDs.Tables[bTableNo].Columns[1].ToString();
cList.ValueMember=oDs.Tables[bTableNo].Columns[0].ToString();

where oDs is DataSet

the purpose is to display the batchname and allow the user to select
multiple batches. To identify the user selection i assigned the BatchID to
Value Member.
Once the user makes his selection i want to get the selected batch id. I
am able to get the display name by verifying if the item is checked or not.
But i dont want the display name. I want to get the IDs associated to that
names. I tried using CheckedIndex collection with out any success.
 
Thank You

But I am not able to get the values of the selected items. When i tried the following:

MessageBox.Show(clstApplications.SelectedValue.ToString());

I got the value of last selected item. But i am not sure how to get the values of all selected items.

Also i am able to get the index of all selected items by doing the following:

System.Collections.IEnumerator myEnumerator = clstApplications.CheckedIndices.GetEnumerator();

while ( myEnumerator.MoveNext() )
{
strIndex = myEnumerator.Current.ToString();
}
Not sure where to go from here

Please Advice

Thanks & Regards
Ram

Ollie said:
To get the index value of the selected item, read the value of the
SelectedIndex property

Ollie

Ram said:
Dear Helpers,

I assigened values to checkedlistbox control in the following way

cList.DataSource=oDs.Tables[bTableNo].DefaultView;
cList.DisplayMember=oDs.Tables[bTableNo].Columns[1].ToString();
cList.ValueMember=oDs.Tables[bTableNo].Columns[0].ToString();

where oDs is DataSet

the purpose is to display the batchname and allow the user to select
multiple batches. To identify the user selection i assigned the BatchID to
Value Member.
Once the user makes his selection i want to get the selected batch id. I
am able to get the display name by verifying if the item is checked or not.
But i dont want the display name. I want to get the IDs associated to that
names. I tried using CheckedIndex collection with out any success.
Please advice. I am new to C#

Thanks & Regards
 
while ( myEnumerator.MoveNext() )
{
strIndex = myEnumerator.Current.ToString();
clstApplications.Items[strIndex ].Value
}


Ram said:
Thank You

But I am not able to get the values of the selected items. When i tried the following:

MessageBox.Show(clstApplications.SelectedValue.ToString());

I got the value of last selected item. But i am not sure how to get the values of all selected items.

Also i am able to get the index of all selected items by doing the following:

System.Collections.IEnumerator myEnumerator = clstApplications.CheckedIndices.GetEnumerator();

while ( myEnumerator.MoveNext() )
{
strIndex = myEnumerator.Current.ToString();
}
Not sure where to go from here

Please Advice

Thanks & Regards
Ram

Ollie said:
To get the index value of the selected item, read the value of the
SelectedIndex property

Ollie

Ram said:
Dear Helpers,

I assigened values to checkedlistbox control in the following way

cList.DataSource=oDs.Tables[bTableNo].DefaultView;
cList.DisplayMember=oDs.Tables[bTableNo].Columns[1].ToString();
cList.ValueMember=oDs.Tables[bTableNo].Columns[0].ToString();

where oDs is DataSet

the purpose is to display the batchname and allow the user to select
multiple batches. To identify the user selection i assigned the BatchID to
Value Member.
Once the user makes his selection i want to get the selected batch id.
I
am able to get the display name by verifying if the item is checked or not.
But i dont want the display name. I want to get the IDs associated to that
names. I tried using CheckedIndex collection with out any success.
Please advice. I am new to C#

Thanks & Regards
 
you are going to hace to cast the object to the correct type in this case
ListItem item.....

do you understand

Ram said:
I tried it but no luck. The reason is there is no definition for 'Value'

Here is the error i received
'object does not contain a definition for Value'

Thanks & Regards

Ollie said:
while ( myEnumerator.MoveNext() )
{
strIndex = myEnumerator.Current.ToString();
clstApplications.Items[strIndex ].Value
}


Ram said:
Thank You

But I am not able to get the values of the selected items. When i
tried
the following:
MessageBox.Show(clstApplications.SelectedValue.ToString());

I got the value of last selected item. But i am not sure how to get
the
values of all selected items.
Also i am able to get the index of all selected items by doing the following:

System.Collections.IEnumerator myEnumerator = clstApplications.CheckedIndices.GetEnumerator();

while ( myEnumerator.MoveNext() )
{
strIndex = myEnumerator.Current.ToString();
}
Not sure where to go from here

Please Advice

Thanks & Regards
Ram

:

To get the index value of the selected item, read the value of the
SelectedIndex property

Ollie

Dear Helpers,

I assigened values to checkedlistbox control in the following way

cList.DataSource=oDs.Tables[bTableNo].DefaultView;
cList.DisplayMember=oDs.Tables[bTableNo].Columns[1].ToString();
cList.ValueMember=oDs.Tables[bTableNo].Columns[0].ToString();

where oDs is DataSet

the purpose is to display the batchname and allow the user to select
multiple batches. To identify the user selection i assigned the
BatchID
to
Value Member.

Once the user makes his selection i want to get the selected batch
id.
I
am able to get the display name by verifying if the item is checked
or
not.
But i dont want the display name. I want to get the IDs associated
to
that
names. I tried using CheckedIndex collection with out any success.

Please advice. I am new to C#

Thanks & Regards
 
Back
Top