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

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

    Hi,
    Windows vb.net

    a. I have added a combo box in data grid view in vb.net, 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,
    Shyam
    tshyamkumarmca@gmail.com
  • #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
    dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
    }

    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;
    dataGridView1.Invalidate();
    }
    }

    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 vb.net, 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)
    conn.Open()
    Dim strQuery As String = "Select Distinct [RegModel] from [tblRegulators]"
    Dim adapter As New OleDbDataAdapter(New OleDbCommand(strQuery , conn))
    Dim ds As New DataSet()
    adapter.Fill(ds)
    cmbregulators.DataSource = ds.Tables(0)
    cmbregulators.DisplayMember = "RegModel"
    cmbregulators.ValueMember = "RegModel"
    End Using


  • Sign In to post your comments