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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:38:25+00:00 2026-05-15T09:38:25+00:00

I have a listview which I have binded (twoWay) to a datatable. The binding

  • 0

I have a listview which I have binded (twoWay) to a datatable. The binding works fine and data is coming up properly on the listview. Now what I want to achieve is a bit complex and I am not even sure whether this can be achieved or now.

My datatable has say 15 columns, and I am showing 5 columns in the lisview. Is it possible that if the user selects a row on listview, I could display other 10 values for that selected row (from the datatable) in textblocks in stackpanel. Is this achievable or am I being too demanding? I tried to achieve this by getting ideas from question here, but couldn’t achieve that.
If it is achievable, can you guys give me ideas on how to proceed with this?

I think this might be achievable by handling listview1_selectionChanged event and populating the textboxes manually, but as I am in a learning stage, I wanted to explore if this can be done through databinding. This way I will know various ways of doing things and can build my concepts in the process.

I am attaching my code below. This is just a test project with one listview having one column.

XAML:

<Window.Resources>
    <Prefs:Tables x:Key="TClass"></Prefs:Tables>
</Window.Resources>
<Grid>
    <StackPanel Orientation="Horizontal">
        <ListView Name="listView1" Background="Transparent" Height="534" BorderThickness="0 0 0 1" VerticalAlignment="Top">
            <ListView.ItemsSource>
                <Binding Source="{StaticResource TClass}" Path="Instance.dtAccounts" Mode="TwoWay"></Binding>
            </ListView.ItemsSource>
            <ListView.View>
                <GridView x:Name="GridView1" ColumnHeaderContainerStyle="{StaticResource GridViewHeader}" AllowsColumnReorder="True">
                    <GridViewColumn Header="Company Name">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock x:Name="txbName" Padding="0 0 5 0" >
                                    <TextBlock.Text>
                                    <Binding Path="NAME">

                                    </Binding>
                                        </TextBlock.Text>
                                </TextBlock>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <StackPanel Name="stkPanel1" Margin="100 0 0 0">
            <TextBlock></TextBlock>
        </StackPanel>
    </StackPanel>
</Grid>

Window1.xaml.cs

public partial class Window1 : Window
{
    DataTable dt = new DataTable();
    public Window1()
    {
        InitializeComponent();
        Tables.Instance.dtAccounts = Worker.LoadAccounts();
    }

}

Class Tables.cs

public class Tables : INotifyPropertyChanged
{
    private static Tables instance;
    public event PropertyChangedEventHandler PropertyChanged = delegate { };
    private DataTable _dtAccounts;

    public Tables()
    {
    }

    // Singleton instance read-only property
    public static Tables Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Tables();
            }
            return instance;
        }
    }

    public DataTable dtAccounts
    {
        get
        {
            return _dtAccounts;
        }
        set
        {
            _dtAccounts = value;
            OnPropertyChanged("dtAccounts");
        }
    }

    private void OnPropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    } 
}

=====================

Final Working Code

I was able to do that with the help of answer provided by Phil. Posting my updated code below, as it might be useful for somebody else.

XAML:

<Grid>
    <StackPanel Orientation="Horizontal">
        <ListView Name="listView1" Background="Transparent" Height="534" BorderThickness="0 0 0 1" VerticalAlignment="Top" SelectionChanged="listView1_SelectionChanged">
            <ListView.ItemsSource>
                <Binding Source="{StaticResource TClass}" Path="Instance.dtAccounts" Mode="TwoWay"></Binding>
            </ListView.ItemsSource>
            <ListView.View>
                <GridView x:Name="GridView1" ColumnHeaderContainerStyle="{StaticResource GridViewHeader}" AllowsColumnReorder="True">
                    <GridViewColumn Header="Company Name">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Name="txbName" Padding="0 0 5 0" >
                                    <TextBlock.Text>
                                    <Binding Path="NAME">

                                    </Binding>
                                        </TextBlock.Text>
                                </TextBlock>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <StackPanel Name="stkPanel1" Margin="100 0 0 0">
            <TextBlock>
                <TextBlock.Text>
                    <Binding Source="{StaticResource TClass}" Path="Instance.SelectedName" Mode="TwoWay">

                    </Binding>
                </TextBlock.Text>
            </TextBlock>
        </StackPanel>
    </StackPanel>
</Grid>

Window1.xaml.cs

public partial class Window1 : Window
{
    DataTable dt = new DataTable();
    public Window1()
    {
        InitializeComponent();
        Tables.Instance.dtAccounts = Worker.LoadAccounts();
    }

    private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ListView lstView = sender as ListView;
        int item = lstView.SelectedIndex;
        Tables.Instance.SetSelectedRow(item);
    }
}

Tables.cs

public class Tables : INotifyPropertyChanged
{
    private static Tables instance;
    public event PropertyChangedEventHandler PropertyChanged = delegate { };
    private DataTable _dtAccounts;
    private string _selectedName;

    public Tables()
    {
    }

    // Singleton instance read-only property
    public static Tables Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Tables();
            }
            return instance;
        }
    }

    public DataTable dtAccounts
    {
        get
        {
            return _dtAccounts;
        }
        set
        {
            _dtAccounts = value;
            OnPropertyChanged("dtAccounts");
        }
    }

    public string SelectedName
    {
        get
        {
            return _selectedName;
        }
        set
        {
            _selectedName = value;
            OnPropertyChanged("SelectedName");
        }

    }

    public void SetSelectedRow(int index)
    {
        int indexNo = index;
        SelectedName = dtAccounts.Rows[index][0].ToString();
    }

    private void OnPropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    } 
}
  • 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-15T09:38:25+00:00Added an answer on May 15, 2026 at 9:38 am

    Here is a basic description of a way you can achieve this. This is not an ideal solution, but should get you on the right track.

    1. Create a field variable in your Tables class that represents a single row in your datatable.
    2. Create a method in your Tables class that sets that field variable to the proper row in your table.
    3. Create properties that expose the values of the row.
    4. Step #2’s method will need to do change notification for all the properties exposed in Step #3 (OnPropertyChanged).
    5. Handle the selection_changed event in your code behind, and from that event handler call the method in your Tables class that sets the selected row.
    6. Bind your text blocks to the
      properties exposed in Step #3.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 426k
  • Answers 426k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I love django but there is an lot of it… May 15, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Did you back it up using SQL only without specifing… May 15, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer There are plenty of examples on the web, but this… May 15, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.