我选中DataGrilView中某条数据,需要对此条纪录数据进行修改,怎么把所需要修改的各项数据填充到窗体的各个控件中?
请问各位这样怎么操作?谢谢!!
请问各位这样怎么操作?谢谢!!
解决方案 »
- 散分--分享一个使用反射+缓存+委托,实现一个不同对象之间同名同类型属性值的快速拷贝 .
- TextBox 中按下组合键的检测
- gridview数据绑定后出现true或false,是因为数据库中的字段类型是bit型
- C#小程序,请高手帮下忙,谢谢了!!!
- 关于数据显示和DataGird控件,请大家提提意见
- C# winform ColorDialog 怎样实现每次进入后焦点在上次选择的颜色
- ???dts
- 求正则表达式代换字符
- RDLC报表LocalReport模式 如何结合分页存储过程
- 有关Dotnet的统一异常处理,高手请入。思归请重视。
- 报错为:用户代码未处理UnauthorizedAccessException,请问这是什么错误???
- DataGridView 绑定到数据集 不能编辑单元格
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
txt_UserID.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
txt_UserName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
txt_Salary.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
cbx_duty.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
}
}
{
btn_update.Checked = false;
if (dgv_ygda.SelectedCells.Count == 0)
{
MessageBox.Show("请选择要修改的数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
string YGName = dgv_ygda.SelectedCells[2].Value.ToString();
Updateygdafrm updateygdafrm = new Updateygdafrm();
updateygdafrm.curr_xm = YGName;
updateygdafrm.curr_ygh = dgv_ygda.SelectedCells[1].Value.ToString();
updateygdafrm.ShowDialog();
}
}private void Updateygdafrm_Load(object sender, EventArgs e)
{
dboperate.BindDropdownjclist("tb_jclist", cb_ldgx, "劳动关系", 11);
dboperate.BindDropdownjclist("tb_jclist", cb_zzmm, "政治面貌", 11);
dboperate.BindDropdownjclist("tb_jclist", cb_zw, "职务", 11);
dboperate.BindDropdownjclist("tb_jclist", cb_hyzk, "婚姻状况", 11);
this.Text = "[" + curr_xm + "]的个人信息";
string strSql = "select * from tb_dalist";
DataSet ds = dboperate.GetTable(strSql);
ds.Dispose();
txt_ygh.Text = ds.Tables[0].Rows[0][2].ToString();
txt_xm.Text = ds.Tables[0].Rows[0][4].ToString();
txt_sfzh.Text = ds.Tables[0].Rows[0][8].ToString();
txt_xb.Text = ds.Tables[0].Rows[0][5].ToString();
txt_nl.Text=ds.Tables[0].Rows[0][6].ToString();
txt_csrq.Text = ds.Tables[0].Rows[0][7].ToString();
cb_zw.SelectedItem = ds.Tables[0].Rows[0][11].ToString();
cb_ldgx.SelectedItem = ds.Tables[0].Rows[0][10].ToString();
cb_zzmm.SelectedItem = ds.Tables[0].Rows[0][9].ToString();
cb_hyzk.SelectedItem = ds.Tables[0].Rows[0][12].ToString();
txt_ssbm.Text = ds.Tables[0].Rows[0][3].ToString();
txt_tel.Text=ds.Tables[0].Rows[0][13].ToString();
txt_mob.Text=ds.Tables[0].Rows[0][14].ToString();
txt_hjdz.Text=ds.Tables[0].Rows[0][15].ToString();
txt_jtdz.Text=ds.Tables[0].Rows[0][16].ToString();
dtp_rzrq.Text=ds.Tables[0].Rows[0][17].ToString();
txt_bz.Text=ds.Tables[0].Rows[0][25].ToString();
}这是我目前写的代码,怎么和你写的联系起来啊
在写个update语句不就好了
try
{
txtHouseNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
cboTypeName.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
txtPrice.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
txtGuestNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
txtBedNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
cboState.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
txtDescription.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
}
catch
{
}
//当点击 dataGridView1 时在文本框显示相应的信息
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (select == 0)
{
try
{
txtHouseNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
cboTypeName.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
txtPrice.Text = dsRoomType.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
txtGuestNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
txtBedNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
cboState.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
txtDescription.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
}
catch
{
}
}
if (select == 1)
{
try
{
txtHouseNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][0].ToString();
cboTypeName.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][1].ToString();
txtPrice.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][2].ToString();
txtGuestNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][3].ToString();
txtBedNumber.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][4].ToString();
cboState.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][5].ToString();
txtDescription.Text = dsRoom.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][6].ToString();
}
catch
{
}
}
}
MyBindingSource.DataSource = dt;
DataGridView.DataSoure =MyBindingSource;
textBox2.DataBindings.Add("Text", MyBindingSource, ".字段A");
...
GV.SelectedRow.Cells[1].Text.ToString();直接赋给你的文本就可以了.