You must Sign In to post a response.
  • Category: .NET

    How to get the event of a combo box in data grid view in


    a. I have added a combo box in data grid view in, in this on selecting the combo box the other values of the data grid view needs to be filled from sql database based on the selected value of the combo box. I don't know how to call the selectedindex value of the combo box to fill the other values of the data grid view.

    b. I have also added a date picker in data gridview. I am not sure how to get the the value of the date time picker.

    Please help me to solve this problem.

    Thanks in advance
    with regards,
  • #769410
    You need to handle the CurrentCellDirtyStateChanged event of the DataGridView. dataGridView1.CurrentCellDirtyStateChanged +=
    new EventHandler(dataGridView1_CurrentCellDirtyStateChanged);

    void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
    if (this.dataGridView1.IsCurrentCellDirty)
    // This fires the cell value changed handler below, if the user selects some value in the combo box

    private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    // combobox column is in the first column, one so I hard coded a 0 (Cells[0]) as below
    DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells[0];
    if (cb.Value != null)
    // Get the data from the database and populate it in the DataGridView. Here I am hardcoding the value of first cell which contains the textbox.
    DataGridViewTextBoxCell tb = (DataGridViewTextBoxCell)dataGridView1.Rows[e.RowIndex].Cells[1];
    tb.Value = cb.Value;

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #769424
    I have been cruising through various discussions today, and have viewed a couple of recordings on the theme, and keep on having issues so I'm asking here. On the off chance that it has been replied, I apologize, however it's not been for my absence of looking. I am new to database and programming subjects, so my wording or stating of the inquiry may not be useful to me.

    In any case, I am building a gear measuring mini-computer in, with information being housed in Access. When I go to each new shape, I will have another bit of gear I am estimating. I have an information matrix see set up in each frame, and a few combo boxes, that will be utilized for questioning the datagrid see. This works fine, I associate with the database fine, yet I can't get the qualities from my db to populate into the sifting comboboxes. I will post a touch of my code, in spite of the fact that I have attempted numerous diverse contentions and strategies.

    Using conn As New OleDbConnection(Yourconnectionstring)
    Dim strQuery As String = "Select Distinct [RegModel] from [tblRegulators]"
    Dim adapter As New OleDbDataAdapter(New OleDbCommand(strQuery , conn))
    Dim ds As New DataSet()
    cmbregulators.DataSource = ds.Tables(0)
    cmbregulators.DisplayMember = "RegModel"
    cmbregulators.ValueMember = "RegModel"
    End Using

  • Sign In to post your comments