DATAgridview怎么在一列中加入 listbox!
DATAgridview怎么在一列中加入 listbox! --------------------编程问答-------------------- http://topic.csdn.net/u/20080314/12/231d7411-4de4-49f7-b070-8ce3afb79f7a.html--------------------编程问答-------------------- 在窗体上放一个 ListBox 设置成不可看的
在datagridview_Click事件中 判断
--------------------编程问答-------------------- 少了一个判断,高度你也可以自己调整一下!
Rectangle rect = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, false);
Listbox.Left = rect.Left;
Listbox.Top = rect.Top;
Listbox.Width = rect.Width;
Listbox.Height = rect.Height;
Listbox.Visible = true;
this.dataGridView1.Controls.Add(lb);
--------------------编程问答-------------------- http://www.codeproject.com/KB/edit/DataGridView.aspx --------------------编程问答-------------------- private void SearchRes_CurrentCellChanged(object sender, EventArgs e)
private void dataGridView1_Click(object sender, EventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0)//如果是第二列,就换成1
{
Rectangle rect = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, true);
listBox1.Left = rect.Left;
listBox1.Top = rect.Top;
listBox1.Width = rect.Width;
listBox1.Height = rect.Height;//高度根据需要调整
listBox1.Visible = true;
this.dataGridView1.Controls.Add(listBox1);
}
}
{//SearchRes是datagridview一个实例
try
{
if(SearchRes.CurrentCell.ColumnIndex == 3)
{//cmb_temp是ComboBox实例
Rectangle reg = SearchRes.GetCellDisplayRectangle(SearchRes.CurrentCell.ColumnIndex, SearchRes.CurrentCell.RowIndex, false);
cmb_temp.Left = reg.Left;
cmb_temp.Top = reg.Top;
cmb_temp.Width = reg.Width;
cmb_temp.Height = reg.Height;
cmb_temp.Visible = true;
string value = SearchRes.CurrentCell.Value.ToString();
cmb_temp.Text = value;
}
else
cmb_temp.Visible = false;
}
catch
{
}
}
你改一下吧,我这个是ComboBox的,替换一下,先实例化一个listbox对象,
补充:.NET技术 , C#