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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:49:36+00:00 2026-06-13T16:49:36+00:00

I do not want use class properties for binding. Why it doesn’t work? How

  • 0

I do not want use class properties for binding.

Why it doesn’t work? How I can fix this. I get empty rows. I have also manually defined columns for DataGrid.

 private void Insert(IList<string> row, DataGrid dG)
        {
            ObservableCollection<IList<string>> data = dG.ItemsSource as ObservableCollection<IList<string>>;
            data.Add(row);
            dG.ItemsSource = data;
        }
  • 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-13T16:49:37+00:00Added an answer on June 13, 2026 at 4:49 pm

    First of all, if you’re using methods to access directly to your DataGrid properties instead of using data binding, then you should use the DataGrid.Items property, not DataGrid.ItemsSource.

    private void Insert(IList<string> row, DataGrid dG)
    {
        dG.Items.Add(row);
    }
    

    But you’ll get empty rows anyway, because the DataGrid has no way of linking each string in your row with the correct column definition.

    I think the best approach would be using a converter:

    Create the RowIndexConverter class inheriting from IValueConverter, and make so your Convert method looks like this:

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        int index = System.Convert.ToInt32(parameter);
        return (value as IList)[index];
    }
    

    For this to work, you have to use it in a Binding to an IList property, like the rows of our DataGrid, and pass an index as the ConverterParameter. The XAML would be something like this:

    <Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Test"
        Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:RowIndexConverter x:Key="rowIndexConverter" />
        </Window.Resources>
        <Grid>
            <DataGrid x:Name="DataGrid">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding ., Converter={StaticResource rowIndexConverter}, ConverterParameter=0}" />
                    <DataGridTextColumn Binding="{Binding ., Converter={StaticResource rowIndexConverter}, ConverterParameter=1}" />
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Window>
    

    Et voila! The values show up. If you want more columns you just have to add them and increment the ConvertParameter. Be careful, as the converter will throw an Exception if the row is not long enough!

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

Sidebar

Related Questions

I want to use the UIGestureRecognizer class inside the iPhone (not the iPad), is
Not sure if this is possible: I want to use datatables to manipulate my
I want to use greasemonkey to scrape wiki data from Last.fm (this is not
What I have is a class with static properties that I want to use
I do not want to use .htaccess. How should I change my Directory attributes?
We do not want to use exit(0) to make the app close, we do
I do not want to use the graphics resources to create the dialog! What
customers does not want to allow user to use back or forward button. Just
I want to use the actual pointer address (not marked volatile) to an object
How to use FileReader not to use BufferReader i want to use File,FileReader for

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.