By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

C# App: Combobox Datatable, Associated Databindings Don't Update

P: 4
Ok this should be simple.
I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database, draws down the existing data, no problem. All the records in the datatable that were the result of a query, I could select from, and the other databound components would display the records contents, no problem..... however.... when i add a new row, the combobox updates, but if i select the NEW item in it, all the databound objects are still pointing to the record to which I had selected prior, and if i make changes to their contents, it updates the fields associated with the priorily selected record, I can still select the original records and edit their contents just fine... but the NEW record's contents never display, and the record to which the databound objects are pointing, never change either... can someone please help before all my hair turns white ? LOL

the setup code that establishes databindings and populates the data table is as follows.
Expand|Select|Wrap|Line Numbers
  1.     mySqlDataAdapter1.SelectCommand =
  2.     new MySql.Data.MySqlClient.MySqlCommand(
  4. mySqlConnection1);
  6.     mySqlDataAdapter1.Fill(dataSet1);
  8.     ComboList = new DataTable();
  10.     ComboList = dataSet1.Tables[0];
  12.     comboBox1.DataSource = ComboList;
  13.     comboBox1.DisplayMember = "DISPLAYVAL";
  14.     comboBox1.ValueMember = "ENTRY_NO";
  17.     FILENAME.DataBindings.Clear();
  18.     FILENAME.DataBindings.Add("TEXT", ComboList, "TYPENAME");
  20.     DESCRIPTION.DataBindings.Clear();
  21.     DESCRIPTION.DataBindings.Add("TEXT", ComboList, "DESCRIPTION");
  23.     FILEEXT.DataBindings.Clear();
  24.     FILEEXT.DataBindings.Add("TEXT", ComboList, "EXTENSION");
  26.     RECLENGTH.DataBindings.Clear();
  27.     RECLENGTH.DataBindings.Add("TEXT", ComboList, "RECORDLENGTH");
  28.     RECLENGTH.CausesValidation = true;
  30.     ISRECDELIM.DataBindings.Clear();
  31.     ISRECDELIM.DataBindings.Add("CHECKED", ComboList, "IS_RECORD_DELIM");
  33.     ISFIELDDELIM.DataBindings.Clear();
  34.     ISFIELDDELIM.DataBindings.Add("CHECKED", ComboList, "IS_FIELD_DELIM");
  36.     ISFLATFILE.DataBindings.Clear();
  37.     ISFLATFILE.DataBindings.Add("CHECKED", ComboList, "IS_FLAT");
  39.     RECDELIM.DataBindings.Clear();
  40.     RECDELIM.DataBindings.Add("TEXT", ComboList, "RECORD_DELIM");
  42.     FIELDDELIM.DataBindings.Clear();
  43.     FIELDDELIM.DataBindings.Add("TEXT", ComboList, "FIELD_DELIM");
I have a button which is labeled new record, its click event handlers is as follows:
Expand|Select|Wrap|Line Numbers
  1. private void button3_Click(object sender, EventArgs e)
  2. {
  4.     DataRow r = ComboList.NewRow();
  6.     r["ENTRY_NO"] = DBNull.Value;
  7.     r["TYPENAME"] = "NEW FILE TYPE";
  8.     r["DISPLAYVAL"] = "X: " + r["TYPENAME"].ToString();
  9.     ComboList.Rows.Add(r);
  10. }
Code mapped to the datatables.oncolumnchanged event is as follows....
Expand|Select|Wrap|Line Numbers
  1. private void UpdateDisplayVal ( Object sender,
  2. DataColumnChangeEventArgs e)
  3. {
  4.     if (e.Column.ColumnName == "TYPENAME")
  5.     {
  6.         e.Row["DISPLAYVAL"] = e.Row["ENTRY_NO"].ToString() + ": " + e.Row["TYPENAME"].ToString();
  7.     }
  8. }
The combobox updates with a value "X: NEW FILE TYPE", when i select a new item in it
none of the other bound objects update with the new value, as they do when i selected
the old item.
Nov 30 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.