Datagridview 某一个cell里…

// 你可以在DataGridView的EditingControlShowing事件中加入如下代码,来给你的ComboxBox加一个事件,在这个事件中处理绑定的问题。
private void variousCostDgv3_EditingControlShowing(object sender, DataGridViewEditingContr olShowingEventArgs e)
{
if (e.Control.GetType().Equals(typeof(DataGridViewComboBoxEdit ingControl)))
{
DataGridViewComboBoxEdit ingControl editingControl = e.Control as DataGridViewComboBoxEdit ingControl;
editingControl.DropDownClosed += new EventHandler(editingControl_DropDownClosed);
}
}

// 然后,在这个事件处理函数中做绑定的处理,我这段代码是动态的改变一个cell的值,并修改对齐方式。你可以改成绑定新Cell的操作。

private void editingControl_DropDownClosed(object sender, EventArgs e)
{
DataGridViewComboBoxEdit ingControl ctl = sender as DataGridViewComboBoxEdit ingControl;
DataRowView drv = this.variousCostDgv3.Rows[ctl.EditingControlRowIndex].DataBoundItem as DataRowView;
drv["unit_name"] = ctl.Text;
drv["VARIOUS_COST_UNIT"] = CommonDataManager.GetChargeUnitData().GetCD(ctl.Text);
if (CommonDataManager.GetChargeUnitData().GetCD(ctl.Text).Equals(EstimateCommon.CHARGE_UNIT_ALL))
{
drv["number"] = "-";
drv["PEOPLE_NUM"] = 1;
this.variousCostDgv3["numberCol3", ctl.EditingControlRowIndex].ReadOnly = true;
this.variousCostDgv3["numberCol3", ctl.EditingControlRowIndex].Style.Alignment = DataGridViewContentAlign ment.MiddleCenter;
}
else
{
drv["number"] = drv["PEOPLE_NUM"];
if (EstimateCommon.ESTIMATE_TYPE_REAL.Equals(mDsForInternal.Tables["CZ_ESTIMATE"].Rows[0]["ESTIMATE_TYPE"].ToString()))
{
this.variousCostDgv3["numberCol3", ctl.EditingControlRowIndex].ReadOnly = false;
}
this.variousCostDgv3["numberCol3", ctl.EditingControlRowIndex].Style.Alignment = DataGridViewContentAlign ment.MiddleRight;
}
this.variousCostDgv3.Refresh();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值