473,394 Members | 1,709 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,394 software developers and data experts.

adding xml data to a combobox

Here's my code thus far:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim objxmldoc As New Xml.XmlDataDocument()
'Load all customer numbers
objxmldoc.Load("s:\sw7\nc\custnum.xml")
Dim onode As Xml.XmlNode
Dim custNum As Xml.XmlNodeList
custNum =
objxmldoc.GetElementsByTagName("AR11_CUSTOMER_NUMB ER")
For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1

ComboBoxCustNum.Items.Add(onode.ChildNodes(inode). InnerText)
Next
End If
Next
End Sub

I'm using this to load data into a combobox and it's working but my
problem is there are duplicate entries in the xml file and so
duplicates are being created in the combobox. How do I suppress/
eliminate duplicates? This is with VB2005.

May 2 '07 #1
2 4078
On May 2, 10:17 am, spowel4 <spow...@gmail.comwrote:
Here's my code thus far:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim objxmldoc As New Xml.XmlDataDocument()
'Load all customer numbers
objxmldoc.Load("s:\sw7\nc\custnum.xml")
Dim onode As Xml.XmlNode
Dim custNum As Xml.XmlNodeList
custNum =
objxmldoc.GetElementsByTagName("AR11_CUSTOMER_NUMB ER")

For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1

ComboBoxCustNum.Items.Add(onode.ChildNodes(inode). InnerText)
Next
End If
Next
End Sub

I'm using this to load data into a combobox and it's working but my
problem is there are duplicate entries in the xml file and so
duplicates are being created in the combobox. How do I suppress/
eliminate duplicates? This is with VB2005.
Try changing this
For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1
ComboBoxCustNum.Items.Add(onode.ChildNodes(inode). InnerText)
Next
End If
Next
to something like this:

For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1
Dim item As Object =
onode.ChildNodes(inode).InnerText
If Not ComboBoxCustNum.Item.Contains(item) Then
ComboBoxCustNum.Items.Add(item)
End If
Next
End If
Next

That way it will look to see if the combobox contains the item before
adding it. I typed that in the message, so beware!

Thanks,

Seth Rowe

May 2 '07 #2
On May 2, 10:37 am, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On May 2, 10:17 am, spowel4 <spow...@gmail.comwrote:
Here's my code thus far:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim objxmldoc As New Xml.XmlDataDocument()
'Load all customer numbers
objxmldoc.Load("s:\sw7\nc\custnum.xml")
Dim onode As Xml.XmlNode
Dim custNum As Xml.XmlNodeList
custNum =
objxmldoc.GetElementsByTagName("AR11_CUSTOMER_NUMB ER")
For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1
ComboBoxCustNum.Items.Add(onode.ChildNodes(inode). InnerText)
Next
End If
Next
End Sub
I'm using this to load data into a combobox and it's working but my
problem is there are duplicate entries in the xml file and so
duplicates are being created in the combobox. How do I suppress/
eliminate duplicates? This is with VB2005.

Try changing this
For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1
ComboBoxCustNum.Items.Add(onode.ChildNodes(inode). InnerText)
Next
End If
Next

to something like this:

For Each onode In custNum
If onode.HasChildNodes Then
Dim inode, inodes As Integer
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1
Dim item As Object =
onode.ChildNodes(inode).InnerText
If Not ComboBoxCustNum.Item.Contains(item) Then
ComboBoxCustNum.Items.Add(item)
End If
Next
End If
Next

That way it will look to see if the combobox contains the item before
adding it. I typed that in the message, so beware!

Thanks,

Seth Rowe
Thanks for the tip Seth, here's my final solution that seems to be
working:

Dim item As Object
custNum =
objxmldoc.GetElementsByTagName("AR11_CUSTOMER_NUMB ER")

For Each onode In custNum
item = New Object
If onode.HasChildNodes Then
inodes = onode.ChildNodes.Count
For inode = 0 To inodes - 1
item = onode.ChildNodes(inode).InnerText
If Not ComboBoxCustNum.Items.Contains(item) Then
ComboBoxCustNum.Items.Add(item)
End If
Next
End If
Next

For some reason, if I declared the item variable within the For loop I
kept getting an error about the object was referencing a null value,
so I declared it further up and I guess the item = New Object line
basically initializes the variable each time?
I'm new to vb so hopefully I'm saying this right.

May 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mendhak | last post by:
Hi All, When you add an object to a combobox, and run the application, you'll get something like this: System.Windows.Forms.Button, Text: Button1 (for example). Is it possible to have...
5
by: Tim | last post by:
I have block of code adding values to dropdown list under if (!Page.IsPostBack) { adding items } else { refreshing data }
5
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound...
1
by: Marco Roberto | last post by:
Hi, is there anyway to add itens into a combobox after this control be bound with a dataset? Regards, Marco
6
by: Juan Pedro Gonzalez | last post by:
I wanted to add a Combobox to a toolbar... Kind of the look you get on VisualStudio's toolbar. I've been able to find some VB 6 samples, but the placeholder option is no longer available for...
6
by: kmercer46 | last post by:
just asking on how to add item data in combobox?? in vb6; combo1.additem "Item 1" combo1.ItemData(combo1.NewIndex) = 1 but how about in .net??
10
by: robingSA | last post by:
Hi...I have a number of Combo Boxes on a form. If one types a name which is not in the table, I want it to add the typed, new item. I am using the following code to do this and it works well,...
0
by: spowel4 | last post by:
VB 2005: Using an xml file as the data source, I need to fill a listbox with data based upon what was selected in a combobox. In other words, my data consists of a list of customers in a...
6
by: Ken Foskey | last post by:
I am brand new to coding C# and Visual Studio. I have worked out how to configure the ComboBox creating my own object however it leave me with a lot of management updating as the table changes....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.