Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Help with displaying partial column name from xml file in combobox using vb.net

Posted on 2016-09-24
13
Medium Priority
?
59 Views
Last Modified: 2016-10-02
Hi,

How do I modify the code below to only display the first 5 records in a table and also from the  to the 12th record. i need to display records in a combobox depending on which categories chosen.

 Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        Dim xmlPath1 As String
        Dim dtsetcol1 As New DataSet
        xmlPath1 = System.IO.Path.Combine(Application.StartupPath + "\MainTest.xml")  'grid1
        dtsetcol1.Clear()
        dtsetcol1.ReadXml(xmlPath1)
        Me.ComboBox3.DataSource = dtsetcol1.Tables(0).Columns(0).ColumnName
    End Sub

Thanks,

Victor
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41816601
Hi Victor;

To part of your question, "How do I modify the code below to only display the first 5 records ", The way you are loading the records does not allow for filtering the rows during the load. You can try removing the rows from the XML before loading or you can try removing/deleting the rows after the rows have been added.

To this part of the question, "also from the  to the 12th record. i need to display records in a combobox depending on which categories chosen", do you mean "from the X  to the 12th record." where X is a number from 0 to 11 and is determine at run time or something else?
0
 

Author Comment

by:vcharles
ID: 41816820
Hi Fernando,

Yes, x is a number from 0 and 11 and determined at run time, how do you remove the columns from the xml file and save yhe new file to a temp table to displays the records?

Thanks,

Victor
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41816831
That would depend on the schema / structure of the XML. Please post an accurate representation of the XML file so I can show you how.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:vcharles
ID: 41816994
Hi Fernando,

Below is the structure of the xml file.

 <Root>
<Fields>
<FieldsN>SN</FieldsN>
</Fields>
<Fields>
 <FieldsN>COUNTRY</FieldsN>
</Fields>
<Fields>
   <FieldsN>AGD4</FieldsN>  
</Fields>
<Fields>
 <FieldsN>FIF</FieldsN>
</Fields>
<Fields>
<FieldsN>NSN</FieldsN>  
</Fields>
<Fields>
 <FieldsN>RN</FieldsN>  
</Fields>
<Fields>
<FieldsN>NAS</FieldsN>
</Fields>
 </Root>

Thanks,

Victor
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41817024
How will you want the list to be filtered / delete items so that they don't show up in the ComboBox?
0
 

Author Comment

by:vcharles
ID: 41824916
Hi Fernando,

Sorry for the late reply, Is it possible for the temp table to only contain the records I want to display?

Thanks,

Victor
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41825377
To your question, "Sorry for the late reply, Is it possible for the temp table to only contain the records I want to display? ", In short the answer is Yes. But that also will depend on what Temp Table is? Is it a .Net DataTable object, or an SQL Temp Table or something else and how you will be filtering the rows for the ones you want to display.
0
 

Author Comment

by:vcharles
ID: 41825390
Hi Fernando,

In previous post you suggested it may be best to delete the rows of the records I don't want to display, I would like to access to new file with deleted rows to a temp table using the .NET DataTable.

Thanks,

Victor
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 41825449
Hi Victor;

In order to get a solution to your question lets try it this way. The original post you posted will not work because of this line of code.
 Me.ComboBox3.DataSource = dtsetcol1.Tables(0).Columns(0).ColumnName

Open in new window

You should have gotten an runtime exception something like "Complex DataBinding accepts as a data source either an IList or an IListSource.", the line of code is returning a data type of string which is the name of the column and not a IList. I changed the last line to what is shown in the code snippet below.
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click                                          
    Dim xmlPath1 As String                                                                                                 
    Dim dtsetcol1 As New DataSet                                                                                           
    xmlPath1 = System.IO.Path.Combine(Application.StartupPath + "\MainTest.xml")  'grid1                                   
    dtsetcol1.Clear()                                                                                                      
    dtsetcol1.ReadXml(xmlPath1)                                                                                            
    DataGridView1.DataSource = dtsetcol1.Tables(0)                                                                         
    Me.ComboBox3.DataSource = dtsetcol1.Tables(0).AsEnumerable().Select(Function(c) c.Field(Of String)("FieldsN")).ToList()                                                                                                                               
End Sub

Open in new window

Is this what you are looking for?
0
 

Author Comment

by:vcharles
ID: 41825472
Yes. Thank you.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41825725
Hi Victor; if that answered your question please close the question. Thank you.
0
 

Author Closing Comment

by:vcharles
ID: 41825738
Thank Yoi.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41825793
Not a problem Victor.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question