none
How to display a message if the user selects the same item in combobox inside datagridview

    Întrebare

  • hi

           i am using combobox inside datagridview .the combobox is bound to the database and if

    the user selects the same item in more than one cell than i want to display a message it's

    repitius. i have tried this code to remove the selected item from the combobox.

    /foreach (int selectedindex in combobox2.SelectedIndex.ToString())
                //{
                //    combobox2.Items.RemoveAt(selectedindex);
                //}

    but it will display the error lik:you can't change the itemcollection property.i thought the error is

    due to the combobox bound to the database.

    if anyone have idea about how to display the message help me.

    thanks in advance

    7 aprilie 2012 04:20

Răspunsuri

  • Hi prabhakar78,
    According to your title and your description, it seems that you are trying to display a message when the user selects a same item.  However, it seems that you want to remove the selected item according to the code. Could you please clarify your requirement?
    According to your last reply, you use ComboBox rather than DataGridViewComboBoxCell in DataGridView, so what do you mean by “if the user selects the same item in more than one cell”? 
    Anyway, if you want to remove the selected item, you can create a new underlying data source, copy each item to it except the selected items and binding to the next Combo Box.
    If you still have any doubt and concern about this issue, please let us know. If I misunderstood you, please kindly elaborate your question.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    9 aprilie 2012 02:14
    Moderator

Toate mesajele

  • So you have populated all comboBoxCells with the same items? And if some item is selected in one cell, this same item cannot be selected in another cell. Am I right?

    Mitja

    7 aprilie 2012 06:20
  • yes 

    mr mitja .i  created a combobox seperately and add it to the gridview and bind the  combobox

    using database within the datagridview. here is my code:

    public  ComboBox combobox2 = new ComboBox();

    combobox2.Hide();

    dataGridView1.Controls.Add(combobox2);

    7 aprilie 2012 08:56
  • Hi prabhakar78,
    According to your title and your description, it seems that you are trying to display a message when the user selects a same item.  However, it seems that you want to remove the selected item according to the code. Could you please clarify your requirement?
    According to your last reply, you use ComboBox rather than DataGridViewComboBoxCell in DataGridView, so what do you mean by “if the user selects the same item in more than one cell”? 
    Anyway, if you want to remove the selected item, you can create a new underlying data source, copy each item to it except the selected items and binding to the next Combo Box.
    If you still have any doubt and concern about this issue, please let us know. If I misunderstood you, please kindly elaborate your question.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    9 aprilie 2012 02:14
    Moderator