在datagridview里添加自定义控件列
1、定义一个控件如:commbox
- //定义下拉列表框、隐藏控件、在datagridview中添加控件
- private ComboBox datacmb=new ComboBox();
- datacmb.Visible = false;
- this.dataGridView1.Controls.Add(datacmb);
2、添加datagridview的CurrentCellChanged事件
- private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
- {
- try
- {
- if (this.dataGridView1.CurrentCell.ColumnIndex == 4)
- {
- Rectangle rec = this.dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, false);
- datacmb.Left = rec.Left;
- datacmb.Top = rec.Top;
- datacmb.Width = rec.Width;
- datacmb.Height = rec.Height;
- datacmb.Visible = true;
- }
- else
- {
- datacmb.Visible = false;
- }
- }
- catch
- {
- //MessageBox.Show(ex.Message);
- }
- }
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 自定义DataGridView表头
- · C#的DataGridView列怎么填充宽度
- · 删除DataGridView行:了索引1处没有值
- · dataGridView另一种复制表的方式
- · DataGridView数据绑定的几种方法
- · The instance of entity type ‘Customer’ cannot be tracked because another instance with the same key value for {‘Id’} is already being tracked.
- · .NET8实时更新nginx ip地址归属地
- · 解决.NET Blazor子组件不刷新问题
- · .NET8如何在普通类库中引用 Microsoft.AspNetCore
- · .NET8 Mysql SSL error
- · ASP.NET Core MVC的Razor视图渲染中文乱码的问题
- · .NETCORE 依赖注入服务生命周期