Bonjour a tous, voici mon probleme...
j'ai un ComboBox et je voudrais simplement faire ComboBox.Items.Clear()
le probleme est que le DataSource du ComboBox est deja definit ...
g un message d'erreur "impossible de modifier la collection d'elements lorsque la propriete datasource est definite"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public void DoInit() { try { _DAMaitre = new OleDbDataAdapter("SELECT * FROM " + _TableName, _OleDbConnection); _DAMaitre.FillSchema(_DataSet, SchemaType.Source, _TableName); _DAMaitre.Fill(_DataSet, _TableName); this.comboBox1.DataSource = _DataSet.Tables[_TableName]; this.comboBox1.DisplayMember = _MemberColName; this.comboBox1.ValueMember = _ValueColName; } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
j'ai pourtant mis le Datasource a null ..??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 private void comboBox1_TextChanged(object sender, EventArgs e) { string SqlCommand = "SELECT * FROM " + _TableName; string text = comboBox1.Text; string condition = " WHERE " + _MemberColName + " LIKE '%" + text+ "%'"; if (text == "") { _DAMaitre.SelectCommand.CommandText = SqlCommand; } else { _DAMaitre.SelectCommand.CommandText = SqlCommand + condition; } comboBox1.DataSource = null; comboBox1.Items.Clear(); _DAMaitre.Fill(_DataSet, _TableName); comboBox1.DataSource = _DataSet.Tables[_TableName]; comboBox1.DisplayMember = _MemberColName; comboBox1.ValueMember = _ValueColName; }
que faire ??
Partager