0

I have a Windows form which has a tab control. Each tab has one data gridview. I would get either a combo box values (array of strings) or a text box value (single string) from the database. Based on the values I am creating either DataGridViewTextBoxColumn or DataGridViewComboBoxColumn dynamically and adding it to the datagridview.

Now I want to handle the events of all the DataGridViewTextBoxColumn and DataGridViewComboBoxColumn in the data gridview in each tab. I want to know how to handle this situation and any sample code would be appreciated.

Patrick
  • 17,669
  • 6
  • 70
  • 85
user209293
  • 889
  • 3
  • 18
  • 27

1 Answers1

0

See

How to bind DataGridViewComboBoxColumn to a OnChange event (C#)

Handle the DataGridView's EditControlShowing event

gridview.EditingControlShowing += DataGridViewEditingControlShowingEventHandler(eventHandlerMethod)

then in the eventHandlerMethod handle the object according to it's type, whether that be combobox or text box:

    void eventHandlerMethod(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (e.Control is ComboBox)
        {

        }
        else if (e.Control is TextBox)
        {

        }
    }
Community
  • 1
  • 1
Lojko
  • 173
  • 1
  • 13