c#中DataGridViewComboBoxColumn如何实现点击右侧按钮显示下拉选项 如题,DataGridViewComboBoxColumn的按钮点击后,不能出现下拉选项,而是先确定焦点,再次点击按钮才会出现下拉选项;我想实现像comboBox一样的功能,点击combobox的按钮,就会显示下拉选项 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上一篇: SQL分页 | 下一篇: 实时统计TextBox录入的字符数 DataGridView内包含ComboBox列 实现选定ComboBox的项数据的联动. 首先要绑定 ComboBox 然后绑定DataGridView DataSet dsProp = new DataSet(); DataSet dsCond = new DataSet(); DataSet dsCond1 = new DataSet(); DataSet dsCond2 = new DataSet(); try ...{ dsProp = App.DbService.GetStandardControlProp(intPrjCode, intStationId, intModuleId, intPointId); dsCond = App.DbService.GetStandardControlCond(intPrjCode,intStationId, intModuleId,1); dsCond1 = App.DbService.GetStandardControlCond(intPrjCode, intStationId, intModuleId, 2); dsCond2 = App.DbService.GetStandardControlCond(intPrjCode, intStationId, intModuleId, 3); dsStationInfo = App.DbService.getStationNameDs(intPrjCode); } catch (Exception ex) ...{ MessageBox.Show(ex.Message, "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dsProp == null || dsCond==null) ...{ MessageBox.Show("数据加载失败!"); return; } DataRow drNew = dsStationInfo.Tables[0].NewRow(); drNew["stationid"] = System.DBNull.Value; drNew["stationnm"] = System.DBNull.Value; dsStationInfo.Tables[0].Rows.InsertAt(drNew, 0); StationID.DataSource = dsStationInfo.Tables[0]; StationID.DisplayMember = "STATIONNM"; StationID.ValueMember = "STATIONID"; MODULEID.DataSource = dsCond.Tables[0]; MODULEID.DisplayMember = "MODULEID"; MODULEID.ValueMember = "MODULEID"; POINTNM.DataSource = dsCond.Tables[0]; POINTNM.DisplayMember = "POINTNAME"; POINTNM.ValueMember = "POINTID"; StationID2.DataSource = dsStationInfo.Tables[0]; StationID2.DisplayMember = "STATIONNM"; StationID2.ValueMember = "STATIONID"; MODULENM2.DataSource = dsCond1.Tables[0]; MODULENM2.DisplayMember = "MODULEID"; MODULENM2.ValueMember = "MODULEID"; POINTNM2.DataSource = dsCond1.Tables[0]; POINTNM2.DisplayMember = "POINTNAME"; POINTNM2.ValueMember = "POINTID"; StationID3.DataSource = dsStationInfo.Tables[0]; StationID3.DisplayMember = "STATIONNM"; StationID3.ValueMember = "STATIONID"; MODULENM3.DataSource = dsCond2.Tables[0]; MODULENM3.DisplayMember = "MODULEID"; MODULENM3.ValueMember = "MODULEID"; POINTNM3.DataSource = dsCond2.Tables[0]; POINTNM3.DisplayMember = "POINTNAME"; POINTNM3.ValueMember = "POINTID"; dgvList.DataSource = InitDT(dsCond.Tables[0].Copy(), 10, 0); dgvList2.DataSource = InitDT(dsCond1.Tables[0].Copy(), 7, 0); dgvList3.DataSource = InitDT(dsCond2.Tables[0].Copy(), 7, 1);注意设定ComboBox的属性:DataPropertyName ,然后调用CellValueChanged事件,此事件主要完成在选定ComboBox时重新绑定要改变的ComboBox. private void dgvList_CellValueChanged(object sender, DataGridViewCellEventArgs e) ...{ dgvCellAutoSetValue(e, dgvList); } private void dgvCellAutoSetValue(DataGridViewCellEventArgs e, DataGridView dgv) ...{ if (e.ColumnIndex == 1) ...{ if (e.RowIndex > -1) ...{ if (dgv.Rows[e.RowIndex].Cells[1].Value == System.DBNull.Value) ...{ return; } DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgv.Rows[e.RowIndex].Cells[2]; try ...{ DataTable DtModule = App.DbService.GetModuleIDInfo(intPrjCode, Convert.ToInt16(dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)).Tables[0]; if (DtModule.Rows.Count > 0) ...{ cell.DataSource = DtModule; cell.DisplayMember = "MODULEID"; cell.ValueMember = "MODULEID"; if (cell.Items.Count > 0) ...{ cell.Value = ((DataRowView)cell.Items[0]).Row[cell.ValueMember]; } } } catch (Exception ex) ...{ MessageBox.Show(ex.Message); } } } else if (e.ColumnIndex == 2) ...{ if (e.RowIndex > -1) ...{ if (dgv.Rows[e.RowIndex].Cells[2].Value == System.DBNull.Value || dgv.Rows[e.RowIndex].Cells[1].Value==DBNull.Value) ...{ return; } int stationid = Convert.ToInt16(dgv.Rows[e.RowIndex].Cells[1].Value); int moduleid = Convert.ToInt16(dgv.Rows[e.RowIndex].Cells[2].Value); DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgv.Rows[e.RowIndex].Cells[3]; try ...{ DataTable DtPoint = App.DbService.GetPointInfo(intPrjCode, stationid, moduleid).Tables[0]; if (DtPoint.Rows.Count > 0) ...{ cell.DataSource = DtPoint; cell.DisplayMember = "POINTNAME"; cell.ValueMember = "POINTID"; if (cell.Items.Count > 0) ...{ cell.Value = ((DataRowView)cell.Items[0]).Row[cell.ValueMember]; } } } catch (Exception ex) ...{ MessageBox.Show(ex.Message); } } } }Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1917889 我已经解决了 可以发送F4信息(sender.sendKey("{F4}"))f4可以像comboBox发送打开item的请求谢谢上面的回答 但sender好像没有sendkey这个方法吧 C#可以使用SendKeys.Send("{F4}"),我已经试过了,可以的 求 C# winform 安装程序制作软件 为什么不同电脑返回不同的SQL结果呢? C# 操作xls 怎样在程序中调用 xls 里的公式进行计算,计算完后进行数据插入xls 文件编码的问题,熟悉的近来看看。 大数量用户上传文件的服务器性能优化。。。 c#中如何制作实时曲线 求大神解决ADO.net 求.Net控件,一次能选择多个文件,并且能批量上传 datagrid问题:中文字段名 我们来讨论一下C#和Java到底谁更有前途吧? 关于DataSet中删除表中某行增加行的问题. 请问C# .NET怎么做像IE一样的多窗口程序?
DataGridView内包含ComboBox列 实现选定ComboBox的项数据的联动.
首先要绑定 ComboBox 然后绑定DataGridView DataSet dsProp = new DataSet();
DataSet dsCond = new DataSet();
DataSet dsCond1 = new DataSet();
DataSet dsCond2 = new DataSet();
try
...{
dsProp = App.DbService.GetStandardControlProp(intPrjCode, intStationId, intModuleId, intPointId);
dsCond = App.DbService.GetStandardControlCond(intPrjCode,intStationId, intModuleId,1);
dsCond1 = App.DbService.GetStandardControlCond(intPrjCode, intStationId, intModuleId, 2);
dsCond2 = App.DbService.GetStandardControlCond(intPrjCode, intStationId, intModuleId, 3);
dsStationInfo = App.DbService.getStationNameDs(intPrjCode);
}
catch (Exception ex)
...{
MessageBox.Show(ex.Message, "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (dsProp == null || dsCond==null)
...{
MessageBox.Show("数据加载失败!");
return;
}
DataRow drNew = dsStationInfo.Tables[0].NewRow();
drNew["stationid"] = System.DBNull.Value;
drNew["stationnm"] = System.DBNull.Value;
dsStationInfo.Tables[0].Rows.InsertAt(drNew, 0); StationID.DataSource = dsStationInfo.Tables[0];
StationID.DisplayMember = "STATIONNM";
StationID.ValueMember = "STATIONID";
MODULEID.DataSource = dsCond.Tables[0];
MODULEID.DisplayMember = "MODULEID";
MODULEID.ValueMember = "MODULEID";
POINTNM.DataSource = dsCond.Tables[0];
POINTNM.DisplayMember = "POINTNAME";
POINTNM.ValueMember = "POINTID"; StationID2.DataSource = dsStationInfo.Tables[0];
StationID2.DisplayMember = "STATIONNM";
StationID2.ValueMember = "STATIONID";
MODULENM2.DataSource = dsCond1.Tables[0];
MODULENM2.DisplayMember = "MODULEID";
MODULENM2.ValueMember = "MODULEID";
POINTNM2.DataSource = dsCond1.Tables[0];
POINTNM2.DisplayMember = "POINTNAME";
POINTNM2.ValueMember = "POINTID"; StationID3.DataSource = dsStationInfo.Tables[0];
StationID3.DisplayMember = "STATIONNM";
StationID3.ValueMember = "STATIONID";
MODULENM3.DataSource = dsCond2.Tables[0];
MODULENM3.DisplayMember = "MODULEID";
MODULENM3.ValueMember = "MODULEID";
POINTNM3.DataSource = dsCond2.Tables[0];
POINTNM3.DisplayMember = "POINTNAME";
POINTNM3.ValueMember = "POINTID";
dgvList.DataSource = InitDT(dsCond.Tables[0].Copy(), 10, 0);
dgvList2.DataSource = InitDT(dsCond1.Tables[0].Copy(), 7, 0);
dgvList3.DataSource = InitDT(dsCond2.Tables[0].Copy(), 7, 1);注意设定ComboBox的属性:DataPropertyName ,然后调用CellValueChanged事件,此事件主要完成在选定ComboBox时重新绑定要改变的ComboBox. private void dgvList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
...{
dgvCellAutoSetValue(e, dgvList);
}
private void dgvCellAutoSetValue(DataGridViewCellEventArgs e, DataGridView dgv)
...{ if (e.ColumnIndex == 1)
...{
if (e.RowIndex > -1)
...{
if (dgv.Rows[e.RowIndex].Cells[1].Value == System.DBNull.Value)
...{
return;
}
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgv.Rows[e.RowIndex].Cells[2];
try
...{
DataTable DtModule = App.DbService.GetModuleIDInfo(intPrjCode, Convert.ToInt16(dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value)).Tables[0];
if (DtModule.Rows.Count > 0)
...{
cell.DataSource = DtModule;
cell.DisplayMember = "MODULEID";
cell.ValueMember = "MODULEID"; if (cell.Items.Count > 0)
...{
cell.Value = ((DataRowView)cell.Items[0]).Row[cell.ValueMember];
}
}
}
catch (Exception ex)
...{
MessageBox.Show(ex.Message);
}
}
}
else if (e.ColumnIndex == 2)
...{
if (e.RowIndex > -1)
...{
if (dgv.Rows[e.RowIndex].Cells[2].Value == System.DBNull.Value || dgv.Rows[e.RowIndex].Cells[1].Value==DBNull.Value)
...{
return;
}
int stationid = Convert.ToInt16(dgv.Rows[e.RowIndex].Cells[1].Value);
int moduleid = Convert.ToInt16(dgv.Rows[e.RowIndex].Cells[2].Value);
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgv.Rows[e.RowIndex].Cells[3];
try
...{
DataTable DtPoint = App.DbService.GetPointInfo(intPrjCode, stationid, moduleid).Tables[0];
if (DtPoint.Rows.Count > 0)
...{
cell.DataSource = DtPoint;
cell.DisplayMember = "POINTNAME";
cell.ValueMember = "POINTID";
if (cell.Items.Count > 0)
...{
cell.Value = ((DataRowView)cell.Items[0]).Row[cell.ValueMember];
}
}
}
catch (Exception ex)
...{
MessageBox.Show(ex.Message);
}
}
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1917889
f4可以像comboBox发送打开item的请求谢谢上面的回答