Search code examples
c#buttonrichtextboxcheckedlistbox

How clear two RichTextBox using CheckedListBox and button


can anybody say me, how can I clear content inside RichTextBox using one button where: CheckedListBox - select which of rtb will be cleared?

How to clear rtb using button and CheckedListBox

I have problem with CheckedListBox - It works for one select position, but not for checked/marked.


Solution

  • private void button1_Click(object sender, EventArgs e)
            {
    
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    if (checkedListBox1.GetItemChecked(i))
                    {
                        string str = (string)checkedListBox1.Items[i];
                        if(str ==  "rtb1")
                        {
                          richTextBox1.Clear();
                          richTextBox1.Focus();
                        }
                         if(str ==  "rtb2")
                        {
                           richTextBox2.Clear();
                           richTextBox2.Focus();
                        }
                    }
                }