Search code examples
c#datagridviewtextboxcelldisplay

Display cell value on textbox in c#


My problem is that it will only display the contents of datagrid on textboxes when i click on the cells under Price column which has a Money DataType all others except for ItemNo is Varchar(100). Please help, thanks

     private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
            DataGridViewRow row = this.dataGridView1.CurrentRow;
            txtDsc.Text = row.Cells["Description"].Value.ToString();
            txtQty.Text = row.Cells["Qty"].Value.ToString();
            txtUnt.Text = row.Cells["Unit"].Value.ToString();
            txtPrc.Text = row.Cells["Price"].Value.ToString();
            txtRmr.Text = row.Cells["Remarks"].Value.ToString();
    }

Solution

  • As the other answer pointed out the code seems to be working fine. I suspect the event is not firing off. Try putting in a breakpoint and investigate that bit.

    I am presuming you need CellClick instead of CellContentClick. Refer CellContentClick event doesn't always work

    Alternatively if you are trying to display the text box values based on the selection on the data grid view, use DataGridView.SelectionChanged Event