按照下面的想法,我应该如何做?
我想在点击DataGrid中的 (X行,Y列) 时,程序在(X行,Y列)的位置显示一个下拉列表框进行选择。
请各位高手帮忙解决这个问题,小弟将重分感谢!
动态创建一个弹出菜单,在x,y处弹出!
说句实话,微软的GRID垃圾不如!你实现了也是白学,微软的工程师如果不是有意不加强GRID功能就是一班猪!几代的GRID都没有给我们一个好一点的希望。
不足之处就不一一数落,越想越气。
用两行显一条记录。
列标题文字居中。
多表头。
DoubleClick响应不如没有,还要自己写一堆代码,而且也不顺畅。
就算绑了菜单,右键出菜单竟是单元格的“复制”微软自带的GRID去死吧!!
。
ComponentOne FlexGrid For .Net是可要实现这些的功能。可没有注册码!
private ComboBox comboControl;
private DataGridTextBoxColumn datagridtextBox;
datagridtextBox = (DataGridTextBoxColumn)datagrid1.TableStyles[0].GridColumnStyles[4]; //指明第几列!
datagridtextBox.TextBox.GotFocus += new EventHandler(this.dgdFunctionArea_GotFocus);
private void dgdFunctionArea_GotFocus(object o, EventArgs e)
{
comboControl = new ComboBox();
comboControl.Cursor= System.Windows.Forms.Cursors.Arrow;
comboControl.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList ;
comboControl.Dock = DockStyle.Fill ;
comboControl.Items.AddRange(new string[6]{"大老虎","可爱的龙","猪头","死老鼠","鸡婆","马"});
datagridtextBox.TextBox.Controls.Add(comboControl);
comboControl.Text =datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber].ToString ();//将GRID的值赋给下拉框。
comboControl.BringToFront();
comboControl.SelectedIndexChanged +=new EventHandler(this.comboControl_SelectedIndexChanged);//增加一事件,好让选择到的值能返回到GRID中。
}
//如何返回值就你自己在这里写了。
private void comboControl_SelectedIndexChanged(object sender, System.EventArgs e)
{ datagrid1[datagrid1.CurrentCell.RowNumber,datagrid1.CurrentCell.ColumnNumber]=comboControl.Text; //将改变的值传回DATAGRID中.
}
试一试喽,祝你好运.