AdvancedHMI Software
General Category => Open Discussion => Topic started by: ajithrengaraj on January 28, 2016, 09:04:31 AM
-
HI
I am new to VB , Basically I am controls guy works with Plc
just started to learn VB to develop an own project
Archie helped me to use the combo box to write the selected item in my PLC
but i would like to make more easier to customer like , giving an option to edit the items in the combo box
Add or delete the items in the combo box
i could see different code in Online to do that since i am not a technical person, its hard to understand
it would be great if anyone explain me in clearly
thanks to all
-
Hello ajithrengaraj,
Try this:
-Add a combo box, text box and button to your form
-Double click the button, which should bring you to the code for the button press
-Add the following to the button press code:
ComboBox1.Items.Add(TextBox1.Text)
The items in a combo box can be referenced by an index (1,2,3,etc) or by item (text that you see). To delete one, you can do this:
' Remove the third item in the list
ComboBox1.Items.RemoveAt(2)
Or if you can remove an item by the specific text that is displayed:
ComboBox1.Items.Remove("This is a test")
Or if you want to remove the currently selected item:
ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex)
-
hi dmroeder
thats amazing , its really pulls me in Vb
looks cool to see how it working
thanks bud
and i would like to do more on that like when i click a button it pops me a new window where i insert a text box to add the item in the combo box list
how to connect the combo box in window1 and text box in window 2
thanks dmroeder
-
I found a problem when i use the above codes
when i close and open the application i loose all my added item and it showing again the default items when i created the combo box
is there any way i can hold the added item in combo box ? even after closing the application
-
ajithrengaraj,
You would have to save them somewhere when you change them and then read them back when you re-start the program.
a Simple text file would suffice, or if you are using a database it would work also.
Let me see if I have some example code around, or can make some up.
You can google FilestreamReader and filestreamwriter to get some examples.
-
Thanks
I found some example code to add and delete line in combo box through text file
but when i add a line , I want to check if the line is already existing in the file .
if it is existing i don't want to add it , it should give me a warning popup message .
i appreciate everyone's help
thanks again
-
Just put all of the defaults in the text file and on startup clear the combo box.
It'll be something like combobox1.items.clear
-
If you use Combox1.FindString("Item you are looking for"), it will return the index of the item you put in the quotes. If it does not find the item, it returns a -1.
So you could do this:
If ComoBox1.FindString("String from text file") = -1 then
ComboBox1.Items.Add("String from text file")
else
'already exists
MessageBox.Show("That one already exists", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
end if
-
hey thanks to both of you
it worked !! now i can understand the VB code little bit ( better than nothing :P )
great work guys :) :)