如何从按钮点击事件的DataGridView中填充文本框 [英] How to Fill TextBoxes from DataGridView on Button Click Event

查看:72
本文介绍了如何从按钮点击事件的DataGridView中填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从DataGridView控件中填写按钮点击事件的数据:





我的代码如下

  for(int i = 0; i< dgv_EmpAttList.Columns.Count; i ++)
{
txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells [i] .Value.ToString( );
txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells [i] .Value.ToString();
txt_LastOutTime.Text = this.dgv_EmpAttList.CurrentRow.Cells [i] .Value.ToString();
txt_TotalHours.Text = this.dgv_EmpAttList.CurrentRow.Cells [i] .Value.ToString();
}


解决方案



尝试为每个文本框分配映射到的单元格:

  txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells [1] .Value.ToString(); 
txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells [2] .Value.ToString();


I want to fill data on button click event from DataGridView Control:

My code like this

for (int i = 0; i < dgv_EmpAttList.Columns.Count; i++)
{
  txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
  txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
  txt_LastOutTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
  txt_TotalHours.Text = this.dgv_EmpAttList.CurrentRow.Cells[i].Value.ToString();
}

解决方案

Looping through your columns probably won't help here.

Try assigning each textbox the cell that it is mapped to:

txt_EnrollNo.Text = this.dgv_EmpAttList.CurrentRow.Cells[1].Value.ToString();
txt_FirstInTime.Text = this.dgv_EmpAttList.CurrentRow.Cells[2].Value.ToString();

这篇关于如何从按钮点击事件的DataGridView中填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆