在DataGridView指定行添加ComboBox
来源:互联网 发布:帝国cms 中华养生 编辑:程序博客网 时间:2024/05/16 10:59
表格样式
------------------------------------------
列1 || 列2
------------------------------------------
静态标签 || TextBox
------------------------------------------
静态标签 || ComboBox
------------------------------------------
静态标签 || ComboBox
------------------------------------------
代码
------------------------------------------
列1 || 列2
------------------------------------------
静态标签 || TextBox
------------------------------------------
静态标签 || ComboBox
------------------------------------------
静态标签 || ComboBox
------------------------------------------
代码
System.Windows.Forms.ComboBox ComboBox1;
private void Form1_Load(object sender, EventArgs e)
{
ComboBox1 = new ComboBox();
ComboBox1.FormattingEnabled = true;
ComboBox1.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6"});
ComboBox1.Name = "ComboBox1";
ComboBox1.TextChanged += new System.EventHandler(this.ComboBox1_TextChanged);
this.DataGridView1.Controls.Add(this.ComboBox1);
this.DataGridView1.AllowUserToResizeRows = false;
this.DataGridView1.AllowUserToResizeColumns = false;
this.DataGridView1.Columns.Add("Column1", "Column1");
this.DataGridView1.Columns.Add("Column2", "Column2");
for (int i = 1; i <= 3; i++)
{
this.DataGridView1.Rows.Add("行" + i.ToString() + " 列1", "行"+ i.ToString() + " 列2");
}
this.ComboBox1.Visible = false;
}
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
switch (e.RowIndex)
{
case 1:
case 2:
this.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
break;
default:
this.ComboBox1.Visible = false;
return;
}
Point p = this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location;
this.ComboBox1.Location = p;
this.ComboBox1.Size = this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
this.ComboBox1.Visible = true;
}
else
{
this.ComboBox1.Visible = false;
}
}
private void ComboBox1_TextChanged(object sender, EventArgs e)
{
this.DataGridView1.CurrentCell.Value = this.ComboBox1.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
ComboBox1 = new ComboBox();
ComboBox1.FormattingEnabled = true;
ComboBox1.Items.AddRange(new object[] {
"1",
"2",
"3",
"4",
"5",
"6"});
ComboBox1.Name = "ComboBox1";
ComboBox1.TextChanged += new System.EventHandler(this.ComboBox1_TextChanged);
this.DataGridView1.Controls.Add(this.ComboBox1);
this.DataGridView1.AllowUserToResizeRows = false;
this.DataGridView1.AllowUserToResizeColumns = false;
this.DataGridView1.Columns.Add("Column1", "Column1");
this.DataGridView1.Columns.Add("Column2", "Column2");
for (int i = 1; i <= 3; i++)
{
this.DataGridView1.Rows.Add("行" + i.ToString() + " 列1", "行"+ i.ToString() + " 列2");
}
this.ComboBox1.Visible = false;
}
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
switch (e.RowIndex)
{
case 1:
case 2:
this.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
break;
default:
this.ComboBox1.Visible = false;
return;
}
Point p = this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location;
this.ComboBox1.Location = p;
this.ComboBox1.Size = this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
this.ComboBox1.Visible = true;
}
else
{
this.ComboBox1.Visible = false;
}
}
private void ComboBox1_TextChanged(object sender, EventArgs e)
{
this.DataGridView1.CurrentCell.Value = this.ComboBox1.Text;
}
- 在DataGridView指定行添加ComboBox
- DataGridView添加ComboBox
- DataGridView添加ComboBox
- 在Winform窗口中为DataGridview单元格添加ComboBox
- DataGridView里动态添加comboBox
- 在dataGridView中显示combobox
- 在DataGridView中加入combobox
- comboBox,listview,DataGridView中添加Item
- 在comboBox中嵌套dataGirdView ; 在dataGridView中嵌套comboBox
- winform 在datagridview中使用 combobox,datetimepicker
- winform 在datagridview中使用 combobox,datetimepicker
- datagridview combobox
- 在DataGridView中添加行号
- 在DataGridView中添加行号
- 在datagridview中添加列
- Datagridview 添加行
- datagridview添加汇总行
- DataGridView动态添加行
- ICOP知识(转)
- 第一次登上csdn,想说几句
- 常用pop3和smtp列表
- WTL资料
- 本地计算机上的OracleOraHome92Agent服务启动后又停止了
- 在DataGridView指定行添加ComboBox
- monorail----ViewComponents
- 弦图判断
- SQL Server学习笔记之 T-SQL研究之[基本查询]
- 如何让 eclipse 全面 使用 Java API中文帮助文档
- 关于iis HTTPERR日志
- Struts中文乱码
- Java 核心技术丛书 卷I 学习心得
- phpMyAdmin中文乱码解决方法