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

  • Home
  • SEARCH
  • 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 8489033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:42:46+00:00 2026-06-10T21:42:46+00:00

I have a simple DataGrid which I am binding to a ObservableCollection and its

  • 0

I have a simple DataGrid which I am binding to a ObservableCollection and its producing black small lines in the Grid with no Data Visible. I am using ObservableCollection as I have the collection being built in RunTime using Reflection.

I am doing something like this
XAML

   <DataGrid ItemsSource="{Binding Data}" />

C#

public ObservableCollection<object> Data
{ 
        get { return _Data; }
        set { 
            this._deals = value;
            this.NotifyPropertyChanged("Deals");
            }
 }
 public Run()
 {
        this.Data = CreateData(typeof(MyRecordClass))   //'MyRecordClass' needs to be passed at runtime
  }


public ObservableCollection<Object> CreateData(Type RecordType)
{
   ObservableCollection<Object> data = new ObservableCollection<object>();  
   var record = Activator.CreateInstance(RecordType);
    // Logic to load the record with Data 
   data.Add(record);
   return data;
}

Is there a way in which I can make the DataGrid read an ObservableCollection without specifying the ColumnNames or create a ObservableCollection object in the CreateData function ?

  • 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-10T21:42:48+00:00Added an answer on June 10, 2026 at 9:42 pm

    Your collection should have public properties, so datagrid could bind columns to it.
    If you use collection type of Object than you have no properies for binding, so the empty rows will be displayed.

    Here is example for you:

    public partial class MainWindow : Window
    {
    public ObservableCollection dataSource;

        public MainWindow()
        {
            InitializeComponent();
    
            this.dataSource = new ObservableCollection<SomeDataSource>();
    
            this.dataSource.Add(new SomeDataSource { Field = "123" });
            this.dataSource.Add(new SomeDataSource { Field = "1234" });
            this.dataSource.Add(new SomeDataSource { Field = "12345" });
    
            this.dataGrid1.ItemsSource = this.dataSource;
        }
    }
    
    public class SomeDataSource
    {
        public string Field {get;set;}
    }
    
    
    
     <DataGrid AutoGenerateColumns="False" Height="253" HorizontalAlignment="Left" Margin="27,24,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="448">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="First" Binding="{Binding Path=Field, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                </DataGrid.Columns>
     </DataGrid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple datagrid to which I am binding a collection using ItemsSource.
I have a Silverlight 4 DataGrid which has its ItemsSource bound to an ObservableCollection
Using MVVM and EF...I have a datagrid binding to a View Model (using ObservableCollection).
I have a simple program which displays a collection on a data grid. When
I have a simple Silverlight app which simply sets a DataGrid's ItemsSource to the
I have a simple Silverlight 5 datagrid bound to a ObservableCollection of objects: <sdk:DataGrid
I have a simple DataGrid which I want the user to add some rows
I have an Editable Data grid which is pulling data from a SQL query
I have created simple DataGrid with 4 columns, which go outside the bounds of
I have simple class with width and height member fields which define number of

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.