Solved

Help with disabling displaying field in combobox if exist in an xml file

Posted on 2016-08-08
6
71 Views
Last Modified: 2016-08-09
Hi,

I'm using the code below to display data from a DataGrid in a combobox:

 ComboBox2.DataSource = (From col As C1.Win.C1TrueDBGrid.C1DataColumn In C1Data.Columns Select col.Caption).ToList()
       

How do I modify the code to display data in the combobox only if the field name in C1Data exist in an xmlmfile?

For example if Main.xml contains the following data elements (NSC,FIF,AGD,UVN) in C1Data contains the following columns((NSC,FIF,NAS, PCS,NMN) I want the dropdown list to only contain (NSC,FIF)

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
  • 3
  • 3
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41748730
Hi Victor;

And what does the schema/structure  of the XML look like?
0
 

Author Comment

by:vcharles
ID: 41748997
Hi Fernando,

The XML format file is in the following format:

<Root>
<Fields>
<NSC></NSC>
<FIF></FIF>
<AGD></AGD>
<UVN></UVN>
</Fields
</Root>

Thanks,

victor
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41749069
Hi Victor;

This should do what you are looking for.
'' Holds the node names of the XML document
Dim xmlTagNames As List(Of String)
'' Load the XML document
Dim xdoc As XDocument = XDocument.Load("Main.xml")
'' Get the names of the nodes
xmlTagNames = (From n In xdoc.Root.Element("Fields").Descendants()
               Select n.Name.LocalName).ToList()
'' Filter out the needed columns.
ComboBox2.DataSource = (From col As C1.Win.C1TrueDBGrid.C1DataColumn In C1Data.Columns
                        Where xmlTagNames.Contains(col.Caption)
                        Select col.Caption).ToList()

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vcharles
ID: 41749755
Hi Fernando,

It works. Thank You.

Is it possible to modify the code using multiple xml files? For example I want to load the combobox with values in the Grid matching fields in both Main.xml and Sub.xml. Other option is to create one xml file from Main and Sub.xml and use the existing code.

If necessary I can open a new issue.

Victor
0
 

Author Closing Comment

by:vcharles
ID: 41749758
Please see my last comments.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41749761
Hi Victory;

I believe you would be better off using one XML file because you will then need to read in two or more XML files then query both and then combine the results into one list.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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