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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:54:32+00:00 2026-06-09T08:54:32+00:00

I have List based on class (id, name, code, price) and im trying to

  • 0

I have List based on class (id, name, code, price) and im trying to add that values to datagrid. Problem is that, datagrid is still empty, i mean look like that:
enter image description here

XAML

<DataGrid AutoGenerateColumns="False" Height="275" HorizontalAlignment="Left" Margin="337,51,0,0" Name="dataGridProducts" VerticalAlignment="Top" Width="403" Foreground="#FF803E3E">
    <DataGrid.Columns>
        <DataGridTextColumn Header="ID" Width="30" />
        <DataGridTextColumn Header="Nazwa" Width="200" />
        <DataGridTextColumn Header="Kod" Width="120" />
        <DataGridTextColumn Header="Cena" Width="100" />
    </DataGrid.Columns>
</DataGrid>

Code Behind:

private void categoryListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    SqlConnection SqlConn = new SqlConnect().ConnectToSql();
    using (SqlConn)
    {
        SqlConn.Open();
        SqlCommand fillCategories = new SqlCommand("...", SqlConn);
        SqlDataReader rdr1;
        rdr1 = fillCategories.ExecuteReader();
        while (rdr1.Read())
        {
            Products p = new Products(rdr1.GetInt32(rdr1.GetOrdinal("ID")), rdr1.GetString(rdr1.GetOrdinal("ProductName")), rdr1.GetString(rdr1.GetOrdinal("Barcode")), rdr1.GetString(rdr1.GetOrdinal("Price")));
            completeProductList.Add(p);
        }
    }
    dataGridProducts.ItemsSource = completeProductList;
}

Is there any solution how to fix it?

  • 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-09T08:54:33+00:00Added an answer on June 9, 2026 at 8:54 am

    You must bind the column to a value in the class of the datagrid items Source

    Example:
    If your datagrid.ItemsSource is a table with 3 columns:

        - ID
        - Name
        - Address
    

    You must bind each column of the datagrid to a column of the table:

        ...
    <DataGridTextColumn Header="ID" Binding="{Binding Path=ID}" Width="Auto" />
    <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" Width="Auto" />
    <DataGridTextColumn Header="Address" Binding="{Binding Path=Address}" Width="Auto" />
    ...
    

    Then you’ll see the bound values of the table.

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

Sidebar

Related Questions

I have a problem with populating an autocomplete list based on a previous input.
I have the below code, which iterates over a list based on a custom
I have a list of objects, that are pre-sorted based on some complex criteria
We have some code which sorts a list of addresses based on the distance
Im trying to learn class-based views, for a detail or list view is not
I have trouble transforming the following code into the new django 1.3 class-based generic
I have a WPF Datagrid binded with list of interface objects. Consider, ClsEmployee class
I have a base class like this: package MyClass; use vars qw/$ME list of
I have a program which places structures in a linked list based on the
I have a list of tuple, the list was sorted based on the first

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.