hi friends,
i have the followng code that loads a table of Roles to the CheckedListBox:
private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add("role_id", typeof(int));
dt.Columns.Add("role_name", typeof(string));
dt.Columns.Add("role_descr", typeof(string));
dt.Rows.Add( new object[] { 1, "Admin", "" } );
dt.Rows.Add( new object[] { 2, "App User", "" } );
dt.Rows.Add( new object[] { 3, "Power User", "" } );
dt.Rows.Add( new object[] { 4, "Maintanence", "" } );
dt.Rows.Add( new object[] { 5, "Supervior", "" } );
dt.Rows.Add( new object[] { 6, "Tester", "" } );
checkedListBox1.DataSource = dt;
checkedListBox1.DisplayMember = "role_name";
checkedListBox1.ValueMember = "role_id"; ;
}
|
When i check the first item in the CheckedListBox, all the other items must be checked, how do i do that?
cheers
Manikavelu VelayuthamPosted Sep 2, 2010, 4:03 AM
just try to find out the first item in checked list box
make the first item in the listbox like "Check All", after that check it out in the following code and process the asusual way.
if (CheckedListbox1[0].Checked == true)
, then make all the items to be checked. Surely it will work.
petre ricardoPosted Sep 2, 2010, 3:54 AM
1. inputCheckedListBox.SelectedItem.ToString(); does not get the item becuase its a DataRowView therefore it never enters the for loop
2. when i do change as below image it goes to an infinite loop:
How do i fix this?
thanks
Manikavelu VelayuthamPosted Sep 2, 2010, 3:35 AM
{
string item = inputCheckedListBox.SelectedItem.ToString();
if (item =="your first choice")
{
for(int i = 0; i < CheckedListBox1.Items.Count; i++)
{
CheckedListBox1.SetItemChecked(i, true);
}
}
}
hope this code helps u
dont forget to mark this post as answered or mark this post as good post if you really like it
petre ricardoPosted Sep 2, 2010, 3:23 AM
anyway i have my best to copy-paste the code but displasy like crud.
hi manik, its a windows application : )
here an image of the code:
cheers
Manikavelu VelayuthamPosted Sep 2, 2010, 3:04 AM
1. Through the .NET code
2, Through Javascript - > if the application is web based.
May i know what application you are developing, web or windows ?