C# .NET - about listbox - Asked By reddyshetty swetha on 16-Apr-10 06:13 AM

 in list box i have some items ......
 if i select one row randomly i want show one messagebox "u want delete that row"....
if i select multiple rows with button randomly i want show one message box "u want delete that rowssssssssssss.................."
help me.........
Sagar P replied to reddyshetty swetha on 16-Apr-10 06:24 AM
You can try something like this;

int cnt = listBox1.SelectedItems.Count; //It will gives you how many items are selected from list
if (cnt == 1)

{

MessageBox.Show("u want delete that row");

}

else if (cnt > 1)

{

MessageBox.Show("u want delete that rowssss");

}
Super Man replied to reddyshetty swetha on 16-Apr-10 08:18 AM

        private void button1_Click(object sender, EventArgs e)

        {

            int i=listBox1.SelectedItems.Count;

            if (i == 1)

            {

                if(MessageBox.Show("do you want to delete this row")== DialogResult.OK)

                {

                    listBox1.Items.Remove(listBox1.SelectedItem);

                }

            }

            else if(i>1)

            {

                 if(MessageBox.Show("do you want to delete all this row")== DialogResult.OK)

                {

                    for(int c=0;c<i;c++)

                    {

                        listBox1.Items.Remove(listBox1.SelectedItem);

                    }

                   

                }

            }

           

        }

Goniey N (Mr. G) replied to reddyshetty swetha on 16-Apr-10 08:35 AM
//Try Below Code

If ( listBox1.SelectedItems.Count == 1)   //You Can Check Here Your Listbox Count Condition Directly

{

      MessageBox.Show("Do You Want To Delete That Row?");

}

else if (listBox1.SelectedItems.Count > 1)

{

      MessageBox.Show("Do You Want To Delete That Rows?");

}



//I Hope This Will Very Helpful You....