using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar.Controls; namespace StarCoder { public partial class CreateWeb : Form { MainForm MF; DataTable dtUserTable; public CreateWeb(MainForm M) { this.Text = Program.Name; MF = M; InitializeComponent(); } private void CreateWeb_Load(object sender, EventArgs e) { this.Name = Program.Name; this.dataGridViewX1.AutoGenerateColumns = false; this.dataGridViewX1.AllowUserToAddRows = false; dtUserTable = MF.GetUserTables(); this.cbxUserTable.DataSource = dtUserTable; dtUserTable.Columns.Add(new DataColumn("nameAndComment")); foreach (DataRow dr in dtUserTable.Rows) { dr["nameAndComment"] = dr["name"].ToString() + "(" + dr["comment"].ToString() + ")"; } this.cbxUserTable.DisplayMember = "nameAndComment"; this.cbxUserTable.ValueMember = "name"; BindUserTable(); } void BindUserTable() { this.dataGridViewX1.DataSource = null; string tb = this.cbxUserTable.SelectedValue.ToString(); DataTable dt = MF.GetTableColumnsInfo(MF.DataBase, tb); this.dataGridViewX1.DataSource = dt; } private void cbxUserTable_SelectedIndexChanged(object sender, EventArgs e) { BindUserTable(); } private void dataGridViewX1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { DataGridViewComboBoxExColumn cbxCol = this.dataGridViewX1.Columns[5] as DataGridViewComboBoxExColumn; cbxCol.DataSource = dtUserTable; cbxCol.DisplayMember = "nameAndComment"; cbxCol.ValueMember = "name"; BindControlType(); } private void pbox_Click(object sender, EventArgs e) { this.Hide(); MF.Show(); } public void BindControlType() { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("id")); dt.Columns.Add(new DataColumn("name")); DataRow dr = dt.NewRow(); dr[0] = "lbl"; dr[1] = "标签"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "rbx"; dr[1] = "单选框"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "cbx"; dr[1] = "复选框"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "ddl"; dr[1] = "下拉列表"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "txt"; dr[1] = "密码输入"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "txt"; dr[1] = "单行文本框"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "txt"; dr[1] = "多行文本框"; dt.Rows.Add(dr); DataGridViewComboBoxExColumn cbxCol = this.dataGridViewX1.Columns[4] as DataGridViewComboBoxExColumn; cbxCol.DataSource = dt; cbxCol.DisplayMember = "name"; cbxCol.ValueMember = "id"; } } }
也就是单击grid中的数据源列的combox控件会调用 cbxUserTable_SelectedIndexChanged,确实想不通是什么原因造成了
解决方案:30分
没有太明白 LZ的意思。
private void cbxUserTable_SelectedIndexChanged(object sender, EventArgs e)
{
BindUserTable();
private void cbxUserTable_SelectedIndexChanged(object sender, EventArgs e)
{
BindUserTable();
}
这个事件,本来就是改变 Combobox的选项后,触发的事件。
就像 button的 click事件一样,你点击了 也会触发 button_click事件。
有什么问题吗?
解决方案:30分
private void cbxUserTable_SelectedIndexChanged(object sender, EventArgs e)
{
BindUserTable();
{
BindUserTable();
}
不想刷新页面 就去掉 combox的 这个change事件
解决方案:20分
你的问题就没有描述清楚,你是不想combox更新后重新绑定列表,还是combox更新后绑定的列表数据没有变化
解决方案:20分
搞不懂为什么要把“页面上有一个combox cbxUseTable”的事件注册到GirdView里面ComboBox列的ComboBox上?想让GirdView里面的ComboBox改变值的时候不引起GridView重新绑定,那就给他一个新的事件,该事件里不写GirdView绑定的代码