473,396 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# windows app - every ComboBox values are changing

pod
298 100+
I have 2 ComboBoxes in a form.
when I change the value of the first, the second combo's value is also changing. What could be causing this?
Oct 23 '07 #1
7 1905
Plater
7,872 Expert 4TB
Are they using the same onchange event?
Are they bound to a dataset?
Oct 23 '07 #2
pod
298 100+
Are they using the same onchange event?
Are they bound to a dataset?
I did not set any onchange event yet but they are bound to the same dataset yes
Oct 23 '07 #3
Plater
7,872 Expert 4TB
Then when you change one, your are changing the current record that they look at, so all of them should change to reflect that.
Oct 23 '07 #4
pod
298 100+
Then when you change one, your are changing the current record that they look at, so all of them should change to reflect that.
so to resolve this, I should create a different dataset (containing the same information), for each combobox, is that it?
Oct 24 '07 #5
Plater
7,872 Expert 4TB
Yes, I think you will have to.
Either that or manually loop through an add your data to the comboboxes so they're not "bound" to a datasource.

Although I recomend making copies of the dataset
Oct 24 '07 #6
pod
298 100+
Yes, I think you will have to.
Either that or manually loop through an add your data to the comboboxes so they're not "bound" to a datasource.

Although I recomend making copies of the dataset
I think I am either misunderstand or misusing datasets, maybe you can clarify this for me;

On my form, I have now 13 questions; the questions are sets in labels and the answers will be collected from comboboxes and textboxes. The labels and textboxes give me no problems (so far). But the comboboxes need options, and I wanted to have the data coming from a datatable in case a new option is desired, then I would not have to modify the form, just add the new option in the database's table.

So correct me if I'm wrong, I would have to create 13 DataSets
Expand|Select|Wrap|Line Numbers
  1. DataSet comboxDS_1 = new DataSet();
  2. DataSet comboxDS_2 = new DataSet();
  3. ...
  4. DataSet comboxDS_13 = new DataSet();
from the same query to provide the same options to the 13 comboboxes in order to keep their selected values different from each other.

What I want is unbounded datasources... I was able to do this in Access but I still need to learn how to do this with .NET


just for the fun of it, here is my code that fills my controls ...

and thank you for the time you take answering my questions


Expand|Select|Wrap|Line Numbers
  1. void load_controls()
  2.         {
  3.             try
  4.             {
  5.                 //labels
  6.                 DataSet labelDS = new DataSet();
  7.                 string labelSQL = @"SELECT * FROM tbl_Label WHERE ynLabel_archive = false " +
  8.                             " AND intLabel_phase = 1 ORDER BY intLabel_id ASC; ";
  9.                 labelDS = classObj.GetDataSet(labelSQL);
  10.                 // object casting
  11.                 System.Windows.Forms.Label curLabel;
  12.                 int rw = -1;
  13.                 int lastposY = 0;
  14.                 int lastHeight = 0;
  15.  
  16.                 //dropdowns
  17.                 DataSet comboxDS = new DataSet();
  18.                 string comboxSQL = @"SELECT * FROM tbl_Status; ";
  19.                 comboxDS = classObj.GetDataSet(comboxSQL);
  20.                 // object casting
  21.                 System.Windows.Forms.ComboBox curCombox;
  22.  
  23.                 //textbox
  24.                 System.Windows.Forms.TextBox curTextBox;
  25.                 foreach (object obj in this.Controls)
  26.                 {
  27.                     switch (obj.GetType().ToString())
  28.                     {
  29.                         case "System.Windows.Forms.ComboBox":
  30.                             //P1_Q1_complete_box.DataSource = newDS.Tables[0];
  31.                             curCombox = ((System.Windows.Forms.ComboBox)obj);
  32.                             if (curCombox.Name.IndexOf("_complete_box") > 0)
  33.                             {
  34.                                 //MessageBox.Show("curCombox:" + curCombox.Name);
  35.                                 curCombox.DataSource = comboxDS.Tables[0];
  36.                                 curCombox.DisplayMember = "strStatus_en";
  37.                                 curCombox.ValueMember = "intStatus_id";
  38.                                 curCombox.Text = "select";
  39.                             }
  40.                             break;
  41.  
  42.                         case "System.Windows.Forms.Label":
  43.                             curLabel = ((System.Windows.Forms.Label)obj);
  44.                 //only apply to certain labels
  45.                             if (curLabel.Name.IndexOf("_box") > 0)
  46.                             {
  47.                                 //this sets the Question ID
  48.                                 rw = Convert.ToInt32(getQuePos(curLabel.Name)) - 1;
  49.                                 curLabel.Text = labelDS.Tables[0].Rows[rw].ItemArray[2].ToString();
  50.                                 curLabel.Text += "\n";
  51.                                 curLabel.Text += "________________________________________________________________________";
  52.  
  53.                             }
  54.                             break;
  55.  
  56.                         case "System.Windows.Forms.TextBox":
  57.                             curTextBox = ((System.Windows.Forms.TextBox)obj);
  58.                             //...
  59.                             break;
  60.                     }//end of switch
  61.  
  62.                 }//End of foreach
  63.  
  64.             }//End of try
  65.             catch (Exception ex)
  66.             {
  67.                 MessageBox.Show("load_controls:" + ex.Message + "\n" + ex.Source + "\n" + ex.TargetSite);
  68.             }
  69.         }
Oct 24 '07 #7
pod
298 100+
after sending the last message, I read again what you said, looked at my code.
I moved 1 line and it solved my problem... :-D
I moved the following line from the initialization to within loop where it gets refreshed and detached I guess. Still unsure what is happening in the background...
Expand|Select|Wrap|Line Numbers
  1. comboxDS = classObj.GetDataSet(comboxSQL);
Thanks again
Oct 24 '07 #8

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

Similar topics

2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
4
by: Michael Turner | last post by:
Hi I am having a problem with a combobox the values are generated from a recordset, I need to beable to change the selected item to the value specified in a configuration file, I have stored the...
6
by: Doug Bell | last post by:
Hi I have a datagrid with a combo box, I need to populate the combo with data dependant on the record value. eg for record 1, field Warehouse = 2R so combo would allow selection of locations...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
2
by: mnms | last post by:
Hi, I'm wondering if it's possible "manually" add an extra value to a combobox list. At the moment I have two fields, one "transparent" is a checkbox that lets you define a colour as...
16
by: ink | last post by:
Hi all, If I have a Windows 32 pointer to and object (Handle) and I know what that object is (Button) can I some how cast that pointer to a type of System.Windows.Forms.Button and then use its...
23
by: Dan Tallent | last post by:
A textbox has a attribute for ReadOnly. This seems like such a simple concept. When a textbox is set to read only the user cannot change the contents of the field. I have been trying to find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.