Reading data from DataGridView in C#

后端 未结 5 1343
礼貌的吻别
礼貌的吻别 2020-12-01 14:40

How can I read data from DataGridView in C#? I want to read the data appear in Table. How do I navigate through lines?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 14:51

    something like

    for (int rows = 0; rows < dataGrid.Rows.Count; rows++)
    {
         for (int col= 0; col < dataGrid.Rows[rows].Cells.Count; col++)
        {
            string value = dataGrid.Rows[rows].Cells[col].Value.ToString();
    
        }
    } 
    

    example without using index

    foreach (DataGridViewRow row in dataGrid.Rows)
    { 
        foreach (DataGridViewCell cell in row.Cells)
        {
            string value = cell.Value.ToString();
    
        }
    }
    

提交回复
热议问题