Solved

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

Posted on 2016-08-08
6
73 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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