DataGridView与TextBox的绑定
1、
private void Query()
{
//dgInOut为DataGridView控件
IList<AccountInfo> accounts = accountBLL.GetList();
this.dgAccount.DataSource = accounts;
//如下代码实现,单击网格时,自动将网格中当前行的相应列赋值给日期、文本等控件的相应属性中。
this.txtCode.DataBindings.Clear();
this.txtCode.DataBindings.Add("Text", accounts, "Code");
this.rbIn.DataBindings.Add("Tag", accounts, "Direction");
this.txtName.DataBindings.Clear();
this.txtName.DataBindings.Add("Text", accounts, "Name").Format += new ConvertEventHandler(Account_Format);
}
{
if (rbIn.Tag.ToString() == "收")
this.rbIn.Checked = true;
else
this.rbOut.Checked = true;
}
{
Query();
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获取客房类型ID
if (e.RowIndex >= 0)
{
typeID = dataGridView1.Rows[e.RowIndex].Cells["ID"].Value.ToString();
//调用业务逻辑层通过类型ID得到客房类型信息
RoomType roomType = manager.GetRoomTypeByTypeID(Convert.ToInt32(typeID));
//回绑数据
this.txtRemark.Text = roomType.Remark;
}
}