新手问题:如何单击datagridview的一行时,得到当前行的值,显示在TEXTBOX控件中 在DATAGRIDVIEW中点击任一行,该行中的数据对应显示在窗体的 一系列TEXTBOX控件中,怎样操作? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用绑定来实现,例如:DataView dv = yourDataTable.DefaultView;yourDataGridView.DataSource = dv;yourTextBox.DataBindings.Add("Text", dv, yourFieldName ); private void dgIrrigateCustomer_Click(object sender, EventArgs e) { if (dgIrrigateCustomer.CurrentRow != null) { foreach (Control ctrl in this.Controls) { string ctrlName = ctrl.Name.Trim(); if (ctrlName.StartsWith("txt")) { ctrl.Enabled = false; } } txtSid.Text = dgIrrigateCustomer.Rows[dgIrrigateCustomer.CurrentRow.Index].Cells[1].Value.ToString(); txtName.Text = dgIrrigateCustomer.Rows[dgIrrigateCustomer.CurrentRow.Index].Cells[2].Value.ToString(); } }dgIrrigateCustomer是datagridview的名称。 綁定:SqlDataAdatper.fill(dt);this.datagrid1.datasource=dt;private void SetGrid(){ txtId.databindings.add("TEXT",dt,"id");..................} 各位老鸟、大侠,请来帮忙分析一下专业,概括一下方向、路线图。 如何取得键盘是输入哪个键? XML保存问题 VS03 打不出switch语句? [疑惑+疑惑]利用Remoting开发的设计问题,欢迎讨论~~~ 如何用C#制作类似Windows资源管理器的程序〉??? 如何获取一个进程的用户? 写的数据库数据查询服务报错(sqlserver),求助,谢谢!!! 【诚邀高手】web request 问题 DataSet如何Update 计算机管理中找不到本地用户和组 请问托管和委托的区别和联系
DataView dv = yourDataTable.DefaultView;
yourDataGridView.DataSource = dv;
yourTextBox.DataBindings.Add("Text", dv, yourFieldName );
{
if (dgIrrigateCustomer.CurrentRow != null)
{
foreach (Control ctrl in this.Controls)
{
string ctrlName = ctrl.Name.Trim();
if (ctrlName.StartsWith("txt"))
{
ctrl.Enabled = false;
}
}
txtSid.Text = dgIrrigateCustomer.Rows[dgIrrigateCustomer.CurrentRow.Index].Cells[1].Value.ToString();
txtName.Text = dgIrrigateCustomer.Rows[dgIrrigateCustomer.CurrentRow.Index].Cells[2].Value.ToString();
}
}
dgIrrigateCustomer是datagridview的名称。
SqlDataAdatper.fill(dt);
this.datagrid1.datasource=dt;
private void SetGrid()
{
txtId.databindings.add("TEXT",dt,"id");
.........
.........
}