且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

要从datagrid Windows窗体访问单元格值

更新时间:2023-12-06 10:28:46

foreach (GridViewRow row in grid.Rows)
{
    foreach (TableCell cell in row.Cells)
    {
        string cellValue = cell.Text.ToString();
    }
}



如果有帮助,请 投票 接受答案 .



Please vote and Accept Answer if it Helped.


int PID = 0;
private void dgrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dgrid.Rows.Count >= 0)
{
    if (e.RowIndex >= 0)
    {
PID = Convert.ToInt32(dgrid.Rows[e.RowIndex].Cells["PID"].Value.ToString());
    }
}
}



这样,您可以获取单元格值..

如果您要将单元格值更新为数据库
使用CellValueChanged事件.



this way u can fetch the cell values..

if u want to update cell value to Database
use CellValueChanged Event..