?
Solved

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

Posted on 2016-08-08
6
Medium Priority
?
75 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 2000 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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