怎么把数据绑定到DataGridView中的ComboBox上并显示出来
展开全部
///<summary///初始化下拉列表框///</summaryprivatevoidInitDGVComboBox(DataGridViewdgv,ComboBoxcbx){m_CbxHelper.BindWeldProcesses(cbx);//绑定数据源到ComboBoxdgv.Controls.Add(cbx);//将ComboBox添加到dgv}//激活某单元格privatevoiddgvDetail21_CellEnter(objectsender,DataGridViewCellEventArgse){if(e.ColumnIndex==2){lastCbxRowIndex=e.RowIndex;lastCbxColIndex=e.ColumnIndex;DisplayComboxOnCell(dgvDetail21,cbxWeldingProcess,e.RowIndex,e.ColumnIndex);}}//离开某单元格privatevoiddgvDetail21_CellLeave(objectsender,DataGridViewCellEventArgse){UpdateComboBoxCellValue(dgvDetail21,cbxWeldingProcess,e.RowIndex,e.ColumnIndex);}///<summary///在制定的单元格显示下拉列表///</summaryprivatevoidDisplayComboxOnCell(DataGridViewdgv,ComboBoxcbx,introwIndex,intcolIndex){DataGridViewCellcell=dgv.Rows[rowIndex].Cells[colIndex];Rectanglerect=dgv.GetCellDisplayRectangle(cell.ColumnIndex,cell.RowIndex,false);cbx.Location=rect.Location;cbx.Size=rect.Size;//根据单元格值,设置ComboBox当前选定值m_CbxHelper.MatchComboBoxValue(cbx,cell.Value.ToString());cbx.Visible=true;}///<summary///更新下拉列表所在单元格值///</summaryprivatevoidUpdateComboBoxCellValue(DataGridViewdgv,ComboBoxcbx,introwIndex,intcolIndex){if(colIndex==2){DataGridViewCellcell=dgv.Rows[rowIndex].Cells[colIndex];if(cell.Value!=null&&cell.Value.ToString()!=cbx.Text){cell.Value=cbx.Text;}cbx.Visible=false;}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询