通过设置Combox的坐标位置实现在datagridview中单击单元格显示下拉框

在datagridview的列设置里,可以设置成下拉类型的,但是有时这个往往不能满足我们的要求,比如需要一些自定义的下拉框,这时想到利用单击单元格来设置下拉框的位置和设置visible来实现。首先获取datagridview的坐标位置,然后获取单元格的Rectangle的相对位置,然后将两个位置相加,就得到单元格的实际屏幕坐标。另外,结构体的LIST绑定到datagridview,是不能改变数据的,可以用类。

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2&&e.RowIndex>-1)
{
int dgvx=dataGridView1.Location.X;
int dgvy=dataGridView1.Location.Y;
int cellx=dataGridView1.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex,false).X;
int celly=dataGridView1.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex,false).Y;
categoryDropDownList1.Location = new Point(dgvx + cellx, dgvy + celly);
categoryDropDownList1.Visible = true;
var source = bindingSource1.DataSource as List<ProductCategoryInfor>;
if (!string.IsNullOrEmpty(source[e.RowIndex].CategoryID))
{
categoryDropDownList1.SelectedValue = source[e.RowIndex].CategoryID;
}
else categoryDropDownList1.SelectedIndex = 0;
}
else categoryDropDownList1.Visible = false;
}

 

转载于:https://www.cnblogs.com/zhoushancai/archive/2012/02/18/2356611.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值