Get the cell value of a GridView row

后端 未结 8 1088
灰色年华
灰色年华 2021-01-01 18:23

I am using the GridView - AutoGenerateSelectButton = \"True\" to select the row in order to get the Column 1 cell value.

I have tried:

         


        
8条回答
  •  萌比男神i
    2021-01-01 19:01

    Windows Form Iteration Technique

    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        if (row.Selected)
        {
            foreach (DataGridViewCell cell in row.Cells)
            {
                int index = cell.ColumnIndex;
                if (index == 0)
                {
                    value = cell.Value.ToString();
                    //do what you want with the value
                }
            }
        }
    }
    

提交回复
热议问题