Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:14:16+00:00 2026-06-12T13:14:16+00:00

I am a .net beginner. I am reading a XML file and showing it

  • 0

I am a .net beginner. I am reading a XML file and showing it in two comboboxes ie., cbProduct and cbBrandName

I need to show text in cbBrandName with respect to the selected text in cbProduct.

I implemented the below code:

DataSet ds = new DataSet();
ds.ReadXml(@"..\..\stock.xml");

cbProduct.DataSource = ds.Tables[0].DefaultView.ToTable(true, "productname");
cbProduct.DisplayMember = "productname";

cbBrandName.DataSource = ds.Tables[0].DefaultView.ToTable(true, "brandname");
cbBrandName.DisplayMember = "brandname";

The above code is showing all the text values in cbBrandName. How to make it to show only the text values which are linked to the selected “productname” column of xml file in cbProduct.

Please Help.

Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:14:17+00:00Added an answer on June 12, 2026 at 1:14 pm

    LINQ looks much more scary than it is. There’s two bits of it being used in Anirudha’s answer, which I’ll try to explain. The first is .Select(x=>. This means “For each thing in the list, replace it with something”. The x represents each item in the list.

    For example:

    new string[]{"a", "b", "c"}.Select(x=>x.ToUpper()); 
    

    turns an array of {“a”, “b”, “c”}, into an array of {“A”, “B”, “C”}. It’s just saying “Take the each thing in the list, and replace it with whatever you get by calling ToUpper() on it.

    The other bit of LINQ is .Where(x=>. That just says “Give me a smaller list which only has things where this statement is true”. So

    new string[]{"a", "b", "c"}.Where(x=>x == "a"); 
    

    will give you a list of {“a”}. Replacing x == "a" with x != "b" will give you a list of {“a”, “c”}. So in the second bit of code, you’re saying “before I do that thing where I replace each item with its productname, I want to filter out anything that doesn’t match what I want to match. Then I transform what’s left.”


    To apply these to the code example, I’ll reformat the lines and comment them.

    // To set the first combo box:
    cbProduct.Items.AddRange( // Add everything we produce from this to the cbProduct list
        doc.Descendants("items") // For each thing that represents an "items" tag and it's subtags
        .Select(x=>x.Element("productname").Value) // Transform it by getting the "productname" element and reading it's Value.
        .ToArray<string>()); // Then convert that into a string[].
    
    
    // To set the second combo box:
    string product2Search=cbProduct.SelectedItem.ToString();// get the currently selected value of cbProduct.
    cbBrandName.Items.Clear(); //clears all items in cbBrandNamedoc
    cbBrandName.Items.AddRange( // Add everything we produce from this to the cbBrandName list
      doc.Descendants("items") // For each thing that represents an "items" tag and it's subtags
      .Where(x=>x.Element("productname").Value==product2Search) // Filter our list to only those things where the productname matches what's currently selected in cbProduct (which we just stored)
      .Select(y=>y.Element("brandname").Value) // Transform it by getting the "brandname" element and reading it's Value.
      .ToArray<string>()); // Then convert that into a string[]
    

    Is that helpful? When I’m coding myself, I like to split long LINQ statements up by putting them on separate lines like this, and then I can just read down the lines: “I get a list WHERE this is true, then SELECT this other thing based on it, and turn it into an ARRAY.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a .net beginner. I need to add some data to xml file
I'm a beginner in WinForms VB NET programming. I need to create text box
I am a .net beginner. I am trying to update my xml file using
I am beginner in .net. I need to show day , month and year
I am a beginner to the ASP.Net MVC. After reading many tutorials and digesting
Good Morning everybody. I'm a beginner in .Net languages and need an example to
I am beginner to asp.net . i need to alert the currently logged in
I’m beginner for ASP.NET MVC , so I need to functioning create and edit
I am beginner in .NET, how can I install NUnit test in Visual Studio 2010? I
I am a beginner in ASP.Net. I am starting a new project using ASP.Net

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.