Programmatically Check an Item in Checkboxlist where text is equal to what i want

后端 未结 5 1014
旧巷少年郎
旧巷少年郎 2020-12-09 03:47

In C#, I am trying to Check an item in a CheckBoxList where the text equals what I require.

I would modify the code to check items that exist in the database.

<
5条回答
  •  忘掉有多难
    2020-12-09 04:16

    //Multiple selection:

              private void clbsec(CheckedListBox clb, string text)
              {
                  for (int i = 0; i < clb.Items.Count; i++)
                  {
                      if(text == clb.Items[i].ToString())
                      {
                          clb.SetItemChecked(i, true);
                      }
                  }
              }
    

    using ==>

    clbsec(checkedListBox1,"michael");
    
    or 
    
    clbsec(checkedListBox1,textBox1.Text);
    
    or
    
    clbsec(checkedListBox1,dataGridView1.CurrentCell.Value.toString());
    

提交回复
热议问题