Datasource and Items not allowed in combo at same time?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1403 Views - Last Post: 28 October 2013 - 12:59 PM Rate Topic: -----

#1 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 10:02 AM

Hi I'm trying to create a program ("trying" being the keyword) where when the user opens a combobox and selects an item it will then be stored which item they selected in a database, there will be 12 choices for that combobox the problem is however that when the combobox is bound with my database, visual studio will not let me add any items it says "Can not modify the items selection when the datasource property is set" so how will I create multiple items that will be sent to my database?

Is This A Good Question/Topic? 0
  • +

Replies To: Datasource and Items not allowed in combo at same time?

#2 _ELement_8215   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 34
  • Joined: 14-December 11

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 10:13 AM

cboBoxesName.Items.Add("Text You Want Shown")
Was This Post Helpful? 0
  • +
  • -

#3 ybadragon   User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 10:24 AM

What code do you have so far?
Was This Post Helpful? 0
  • +
  • -

#4 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 11:12 AM

d.Add("NULL OPCODE", 0)
d.Add("HEAT", 1)
d.Add("CARBON", 2)
d.Add("RAMP", 3)
d.Add("SOAK", 4)
d.Add("TEMP LIMIT TIME", 5)
d.Add("CARBON LIMIT TIME", 6)
d.Add("AMONIA EVENT", 7)
d.Add("END OF CYCLE EVENT (G 192)", 8)
d.Add("SPARE EVENT", 9)
d.Add("PROBE BURNOFF EVENT (G 199)", 10)
d.Add("TEMP DEVIATION", 11)
d.Add("CARBON DEVIATION", 12)

For Each item In d
ComboBox1.Items.Add(item.Key)
ComboBox2.Items.Add(item.Key)
ComboBox3.Items.Add(item.Key)
ComboBox4.Items.Add(item.Key)
ComboBox5.Items.Add(item.Key)
ComboBox6.Items.Add(item.Key)
ComboBox7.Items.Add(item.Key)
ComboBox8.Items.Add(item.Key)
ComboBox9.Items.Add(item.Key)
ComboBox10.Items.Add(item.Key)
ComboBox11.Items.Add(item.Key)
ComboBox12.Items.Add(item.Key)
ComboBox13.Items.Add(item.Key)
ComboBox14.Items.Add(item.Key)
ComboBox15.Items.Add(item.Key)
ComboBox16.Items.Add(item.Key)
ComboBox17.Items.Add(item.Key)
ComboBox18.Items.Add(item.Key)
ComboBox19.Items.Add(item.Key)
ComboBox20.Items.Add(item.Key)
ComboBox21.Items.Add(item.Key)
ComboBox22.Items.Add(item.Key)
ComboBox23.Items.Add(item.Key)
ComboBox24.Items.Add(item.Key)
ComboBox25.Items.Add(item.Key)
ComboBox26.Items.Add(item.Key)
ComboBox27.Items.Add(item.Key)
ComboBox28.Items.Add(item.Key)
ComboBox29.Items.Add(item.Key)
ComboBox30.Items.Add(item.Key)
ComboBox31.Items.Add(item.Key)
ComboBox32.Items.Add(item.Key)
ComboBox33.Items.Add(item.Key)
ComboBox34.Items.Add(item.Key)
ComboBox35.Items.Add(item.Key)
ComboBox36.Items.Add(item.Key)
ComboBox37.Items.Add(item.Key)
ComboBox38.Items.Add(item.Key)
ComboBox39.Items.Add(item.Key)
ComboBox40.Items.Add(item.Key)

Next




Ok so I'll go into a little more detail there are 40 combo boxes each with those choices in the dictionary, each combo box represents a column in my database. There are also 200 rows each row represents a program so i will have (200) possible. the reason I have those options stored in the dictionary with number values is because depending on what choice the user selects its corresponding value will be sent to my control logix PLC (I don't know if anyone here programs plcs that's a whole other topic lol)


Now since I have my combo boxes bound to my data-table (i did not use code i used the properties window) and I'm adding items into it i got the exception message A first chance exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll so in the debug menu i checked common language run time exceptions to see what was going on and that's when I figured out you can't have insert items into your combo box when it is using a data source.

So my question comes in how can I populate the combo box so when the user selects heat or carbon or ramp their selection will be stored in my database.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 12:02 PM

Without understanding this completely, it would appear you would want to add the appropriate selections to the datatable that the combobox is bound to. Otherwise, I'm not sure why you would try to add something to a combobox that is bound to a datatable since you ultimately want the results of the updated datatable saved back to the database.

Looks like you're building a carbonitride/carburize cycle selector/generator for heat treat.
Was This Post Helpful? 0
  • +
  • -

#6 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 12:25 PM

It's a recipe program for a heat treating furnace each combo box represents a step when all of the steps are sent to the plc my code in the plc knows what to do for example take 10 hours to ramp up to 1800 degrees then heat for so longs at 1800 degrees then add 1.05 of carbon potential then soak in atmosphere for 2 hours. So then the first combo would be ramp and then the next would be heat, then carbon, then soak, then the last would say end of cycle and my plc would know there's no more steps.

There are many parts we do with these heat treat furnaces so i want to be able to save up to 200 programs for different parts, but without being able to add items to the combo while it has a datasource for my database I'm not sure how to store the user selection to the database.
Was This Post Helpful? 0
  • +
  • -

#7 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2559
  • View blog
  • Posts: 10,277
  • Joined: 03-December 12

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 01:28 PM

I think what you are looking for is an UNbound combobox. Create a list or array, whichever you prefer, with the possible choices. Depending on how you want the save to activate, save the selecteditems to the corosponding field in the database as a new row. Let me know if you need more direction.

Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 01:48 PM

I'm thinking more like astonecipher, Instead of a bunch of comboboxes, I would set up a listview or datagridview and build the recipe. Then move through the rows of the list, saving them as steps to the database, using the partnumber for the foreign key.

Then you would select the part number and pull from the recipe table based on that part number all the steps of the recipe.

So your layout would be something like
[CycleType] [Value]       [Add Step]



CycleType being a single combobox with HEAT, CARBON, RAMP, SOAK, END CYCLE etc. Value being the Types setting and Add Step being a button to add to the list

So you would select RAMP in the combobox and enter 1800 in the value box and click Add Step to add to the list.
Once you click the Add Step button, you set the combobox's index to -1 and clear the textbox ready for the next step.

Once you have everything in the list, you could click a Save Recipe button and prompt for a part number and then iterate through the list to add everything.

This will give you the option of editing, moving steps, etc to get everything right before you save.

EDIT: Forgot to mention, doing it this way would allow you to save a lot more than 200 recipes.

This post has been edited by CharlieMay: 25 October 2013 - 01:50 PM

Was This Post Helpful? 0
  • +
  • -

#9 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 02:46 PM

Thanks for the input! I'm thinking unbound combobox will be the way to go instead of a list box only because in the menu there is a button that says Send to PLC (sends items in comboboxes to PLC), basically I'm communicating to my PLC via ethernet and that's why all my choices have values assigned to them in the dictionary (All of my PLC tags only take in numbers) so my code looks like when the button is clicked

EthernetIPforCLXCom1.Write("N20[5]", CStr(d(ComboBox1.Text)))
EthernetIPforCLXCom1.Write("F21[5]", TextBox1.Text)

the N20[5] and F21[5] are tag names in my PLC the N20 is for the step and the F21 is for the step value like 1800 Degrees or 5.4 hours

I could be wrong about the list box idea! This is my first program I've ever made in structured text format, I'm a PLC programmer ha.

I'm going to have to do some research on that unbound combo and how to write its selections to my database because so far ive been binding my combos to my database by using the properties I don't know how to actually code the combos writing information to my database.
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2559
  • View blog
  • Posts: 10,277
  • Joined: 03-December 12

Re: Datasource and Items not allowed in combo at same time?

Posted 25 October 2013 - 03:10 PM

Depending on how far you want / need the program to go...

Have a data table tblOperations with fields, PLC_code, PLC_command
Primary_key = PLC_code

Databind the combo boxes (look into arrays of comboboxes and for each loops by the way).
Combobox.valuemember = "PLC_code"
Combobox.displaymember = "PLC_command"

The display member is what you actual see but, what is stored is the code the system needs to operate.

Then another table tblrecipe that stores the entries. That way IF and I have no idea about what you do, if a new operation can occur it can be selectable from the listings.
Was This Post Helpful? 1
  • +
  • -

#11 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Re: Datasource and Items not allowed in combo at same time?

Posted 28 October 2013 - 05:37 AM

Ok, I understand having the one table with all my options such as Heat, Carbon, Etc. to fill my comboboxes, and then I also understand having a second table to store what the user selected, the only thing i'm not getting is if my comboboxes are basically bound to or filled with the first table how will i store whats in them to the second table? would that be a piece of code I have to write? or?..
Was This Post Helpful? 0
  • +
  • -

#12 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2559
  • View blog
  • Posts: 10,277
  • Joined: 03-December 12

Re: Datasource and Items not allowed in combo at same time?

Posted 28 October 2013 - 05:47 AM

You would write an insert command for the recipe table if either every combo box if not -1, or a button click. Most of the time, at least for me, I prefer to write the connection and cmds and not use what can be written in VS. You have more control that way.
Was This Post Helpful? 1
  • +
  • -

#13 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Re: Datasource and Items not allowed in combo at same time?

Posted 28 October 2013 - 05:52 AM

well if i can just use that piece of code for inserting whats in the combo to the database I don't even need that first database then do I? i can just fill the combo using code
Was This Post Helpful? 0
  • +
  • -

#14 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2559
  • View blog
  • Posts: 10,277
  • Joined: 03-December 12

Re: Datasource and Items not allowed in combo at same time?

Posted 28 October 2013 - 06:01 AM

No you don't need it. Like I said, I don't know exactly what you do, if another process was added every combobox would need to be updated. And you will need decision statements to set the code value without the table.
Was This Post Helpful? 0
  • +
  • -

#15 JesseMcNeely   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-September 13

Re: Datasource and Items not allowed in combo at same time?

Posted 28 October 2013 - 07:17 AM

ok well i started to look into the code of inserting updating and deleting records from a database and it seems pretty straight forward but i foresee a problem now. If my comboboxes aren't using a binding source then I can't using a binding navigator so for my up to 200 programs I will have to have a listbox or combo box with the programs listed and code saying if program x is selected insert combo1.text to column1 where id = x... now remember i have 40 combo boxes 40 text boxes and want up to 200 hundred programs, so i can't even imagine how long that code would have to be.., any ideas?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2