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 3785396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:31:19+00:00 2026-05-19T11:31:19+00:00

I’m new to C# and WPF so hopefully this is a simple issue. I

  • 0

I’m new to C# and WPF so hopefully this is a simple issue.

I have a listview which retrieves data from a SQL Server table.

<ListView Width="450" Margin="10" Grid.Row="1" ItemsSource="{Binding Path=Table}" Name="FIData" SelectionChanged="FIData_SelectionChanged">
       <ListView.View>
         <GridView>
           <GridViewColumn Header="FI #" DisplayMemberBinding="{Binding Path=Id}"/>
           <GridViewColumn Header="FI Short Name" DisplayMemberBinding="{Binding Path=ShortName}"/>
           <GridViewColumn Header="FI Long Name" DisplayMemberBinding="{Binding Path=LongName}"/>
           <GridViewColumn Header="Last Load Date" DisplayMemberBinding="{Binding Path=MostRecentEffectiveDate}"/>
         </GridView>
       </ListView.View>
    </ListView>

SqlConnection con = new SqlConnection();
    SqlDataAdapter ad = new SqlDataAdapter();
    SqlCommand cmd = new SqlCommand();

    string strSql = "SELECT Id, ShortName, LongName, MostRecentEffectiveDate FROM Institutions";


public void BindData()
    {
        cmd.CommandText = strSql;
        ad.SelectCommand = cmd;
        con.ConnectionString = "Data Source=DEVDB\\ABC; Initial Catalog=Cat1; Integrated Security=True";
        cmd.Connection = con;
        DataSet ds = new DataSet();
        ad.Fill(ds);
        FIData.DataContext = ds.Tables[0].DefaultView;
        con.Close();
    }

private void Button_Click(object sender, RoutedEventArgs e)
    {
        BindData();
    }

When clicking a button, the BindData method is called and my list view populates just fine. My problem is I don’t know how to retrieve the data values from the selected list item.

In all of the other examples users are either populating their data from properties in the C# code or XML or some other source. I’m thinking that perhaps one of my problems is I don’t understand objects quite right, but I was hoping someone could show me how I go about getting specific values from the selected list. I want to use one of those values later on.

Thanks,

Jason

  • 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-05-19T11:31:20+00:00Added an answer on May 19, 2026 at 11:31 am

    Here, when you do:

    FIData.DataContext = ds.Tables[0].DefaultView;

    it maps the actual DataTable with virtual properties, which can be used for data-binding scenarios like yours.

    But to answer your question on how you can retrieve the data values, I think you are pretty close because you have FIData_SelectionChanged event for your listview. In that event:

    private void FIData_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      var myListView = sender as ListView;
      if(myListView != null)
      {
        var selectedItem = myListView.SelectedItem;
    
        //selectedItem should have an array, which contains data values for the bound object.
      }
    }
    

    you should inspect the selectedItem above in the debugger and look at what data it contains.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.