vs2003,winform中,已经通过重载写出了datagrid中的combobox列,现在需要实现帮定数据 到combobox的DisplayMember,显示ValueMember属性中的文字,并且在数据修改提交时,将DisplayMember中的数据提交出去。因为在datagrid上榜定的datatable,使用适配器的update方法更新到数据库,一直没有实现,各位提供思路,多谢
解决方案 »
- 控件置顶的问题以及panel挡住其他控件问题
- 请问如何让空间在附近出现
- 关于dataGridView删除的问题
- 关闭页面问题 没有几句话 就是不知道应该怎么做 谢谢大家
- 配置文件问题!!!!
- 急啊~大家帮帮忙
- C# WINFORM中,怎么获取DataGird的当前行,列(就是光标所选择中的一个单元格)Location的值,谢谢!在线等待结贴
- 线程同步问题,刷新ListView出无法try过去的错!!!!
- 问一个简单的问题?怎么把一个字符转成Unicode码?
- 那里有关于c#数据库方面的书和网站呀
- 请问怎么用编程的方式将文本框的ScrollBar竖向移动最底部
- 请哪位朋友帮帮忙,帮我解决该问提,谢谢!
不知道这个对你有没有用
更新就不需要了adapter了
用command吧
简单易行
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q
this.Drop_CalendarSYR.DisplayMember = "Value";
this.Drop_CalendarSYR.ValueMember ="Key";
if(r_Dto.CalendarSYRList.Rows.Count>0)
{
foreach(CalendarMConfirmDisplayInfoDto.CalendarSYRListRow Row in this.r_Dto.CalendarSYRList)
{
DictionaryEntry de = new DictionaryEntry(Row.CalendarSYRKBN,Row.CalendarSYRK);
this.Drop_CalendarSYR.Items.Add(de);
}
}
if(this.Drop_CalendarSYR.SelectIndex >-1)
{
DictionaryEntry de = (DictionaryEntry )this.Drop_CalendarSYR.SelectItems;
Row.value = (string)de.value;
Dto.DatatableRow.Add(Row);
}
给段代码 仅供参考不知道适不适合你
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName="grp_sln";
// Set other properties.
//ts1.AlternatingBackColor = Color.LightGray;
//
// Add 2 cols with textbox column style
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
TextCol.MappingName="zbh";
TextCol.HeaderText="小组编号";
TextCol.Width=100;
ts1.GridColumnStyles.Add(TextCol);
TextCol.ReadOnly=true; TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "zmc";
TextCol.HeaderText = "小组名称";
TextCol.Width = 100;
ts1.GridColumnStyles.Add(TextCol);
TextCol.ReadOnly=true;
// Step 2 - Use the combo column style
// Add 1 col with combo style
DataGridComboBoxColumn ComboTextCol = new DataGridComboBoxColumn(new ComboValueChanged(MyComboValueChanged));
ComboTextCol.MappingName = "hpzbh";
ComboTextCol.HeaderText = "选择互评小组编号";
ComboTextCol.Width = 140;
ComboTextCol.NullText="";
ts1.GridColumnStyles.Add(ComboTextCol); // Step 3 - Additional setup for Combo style
// a) make the row height a little larger to handle minimum combo height
ts1.PreferredRowHeight = ComboTextCol.ColumnComboBox.Height + 1;
// b) Populate the combobox somehow. It is a normal combobox, so whatever...
ComboTextCol.ColumnComboBox.Items.Clear();
if(LevelOfNode(this.treeView5.SelectedNode)==2)
{
foreach(DataRow dr in ds.Tables["grp_sln"].Select("bh='"+this.treeView5.SelectedNode.Tag.ToString().Trim()+"'"))
{
ComboTextCol.ColumnComboBox.Items.Add(dr["zbh"]);
}
}
// c) set the dropdown style of the combo...
ComboTextCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList; //add the custom table style to the datagrid table styles
dataGrid3.TableStyles.Add(ts1);
//dataGrid3.TableStyles.Remove(ts1);
private void GetFocus(int row,int col)
{
///先把焦点移动到DataGrid
this.dgdFunctionArea.Focus();
///把焦点移动到DataGridCell
DataGridCell dgc = new DataGridCell(row,col);
this.dgdFunctionArea.CurrentCell = dgc;
DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)dgdFunctionArea.TableStyles[0].GridColumnStyles[col]; ///设置焦点 dgtb.TextBox.Focus();
}
private void cmbFunctionArea_SelectionChangeCommitted(object sender, EventArgs e)
{
this.dgdFunctionArea[this.dgdFunctionArea.CurrentCell] = ((ComboBox)sender).SelectedValue.ToString();
}
private void AddCustomDataTableStyle()
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "rebate";
ts1.AlternatingBackColor = Color.LightGray;
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn(); ComboBox cmbFunctionArea = new ComboBox();
strCon = "SELECT STR(STORE_NO) + ' ' + STOREID AS STOREID,STORE_NO FROM t_b_STORE";
SqlDataAdapter dac = new SqlDataAdapter(strCon, strConns);
DataSet dsc = new DataSet();
dac.Fill(dsc,"store");
cmbFunctionArea.DataSource = dsc ;
cmbFunctionArea.DisplayMember = "store.STOREID";
cmbFunctionArea.ValueMember = "store.STORE_NO";
cmbFunctionArea.Cursor = Cursors.Arrow;
cmbFunctionArea.DropDownStyle= ComboBoxStyle.DropDownList;
cmbFunctionArea.Dock = DockStyle.Fill;
cmbFunctionArea.SelectionChangeCommitted += new EventHandler(cmbFunctionArea_SelectionChangeCommitted);
TextCol.TextBox.Controls.Add(cmbFunctionArea);
TextCol.MappingName = "STORE_NO";
TextCol.HeaderText = "STORE_NO";
TextCol.Width = 120;
ts1.GridColumnStyles.Add(TextCol);
}