How to create Master Detail from datagridview

后端 未结 1 462
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 15:06

this code inserts in the database

 private void btnSave_Click(object sender, EventArgs e)
    {
        byte[] imageBt = null;
        FileStream fstream = new F         


        
相关标签:
1条回答
  • 2021-01-24 15:27

    Note:

    • In CellClick event you should check if click is not on row header or column header
    • e.RowIndex is row index of clicked cell, and e.ColumnIndex is index of column of clicked cell
    • To get values of clicked row you can use:
      • yourDGV.Rows[e.RowIndex].Cells["GridColumnName"].value
      • yourDGV.Rows[e.RowIndex].Cells[2].Value
      • ((DataRowView)yourDGV.Rows[e.RowIndex].DataBoundItem)[2]
      • ((DataRowView)yourDGV.Rows[e.RowIndex].DataBoundItem)["DataTableColumnName"]
    • I didn't have any idea about why you fill abaanaCC in CellClick because you load data in form load event and so all values including CCImage is present id your data table. So I removed it. It seems that you should fill it only when you want to load data not here in cell click.

    For example your code may like this:

    private void abaanaCCDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        if (e.RowIndex < 0 || e.ColumnIndex < 0)
            return;
    
        this.Ptxtspn_code.Text = this.abaanaCCDataGridView.Rows[e.RowIndex].Cells[this.dataGridViewTextBoxColumn2.Name].Value.ToString();       
        byte[] mydata = (byte[])this.abaanaDataSet.abaanaCC.Rows[r.RowIndex]["CCImage"];
        MemoryStream stream = new MemoryStream(mydata);           
        this.PpicBox.Image =Image.FromStream(stream);
    }
    
    0 讨论(0)
提交回复
热议问题