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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:31:53+00:00 2026-05-14T23:31:53+00:00

I’m trying to get data from file. The file first has three lines of

  • 0

I’m trying to get data from file. The file first has three lines of text that describes the file, then there is a header for the data below. I’ve managed to extract that. What I’m having problems is getting the data below the header line. The data below the header line can look like “1 2 3 4 5 6 7 8 9 abc”.

DataGrid dataGrid1 = new DataGrid();
masterGrid.Children.Add(dataGrid1);

using (TextReader tr = new StreamReader(@filename))
{
    int lineCount = 1;
    while (tr.Peek() >= 0)
    {
        string line = tr.ReadLine();
        {
            string[] data = line.Trim().Split(' ');

            Dictionary<string, object> sensorData = new Dictionary<string, object>();

            for (int i = 0, j = 0; i < data.Length; i++)
            {
                //I know that I'm delimiting the data by a space before.
                //but the data from the text file doesn't necessarily have
                //just one space between each piece of data
                //so if I don't do this, spaces will become part of the data.
                if (String.Compare(data[i]," ") > 0)
                {
                    sensorData[head[j]] = data[i];
                    j++;
                }
            }

            sensorDatas.Add(sensorData);

            sensorData = null;

        }
        lineCount++;
    }
}

dataGrid1.DataContext = sensorDatas;

I can’t figure out why this doens’t work. If I change “dataGrid1.DataContext = sensorDatas;” to “dataGrid1.ItemsSource = sensorDatas;” then I get the data in the proper columns, but I also get some Raw View data such as: Comparer, Count, Keys, Values as columns, which I don’t want.

Any insight?

  • 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-14T23:31:54+00:00Added an answer on May 14, 2026 at 11:31 pm

    When you use the DataContext property on a control in WPF, that is used to set the data source that the control will use when populating properties which have bindings associated with them.

    This is a very different thing than setting the ItemsSource property to indicate the data you wish to show in the grid. Yes, bindings will still be used, but they are used in a different way for the data that is shown in the grid, not the data that is used to drive the configuration of the grid itself (which is what DataContext does).

    Rather, it seems that you are allowing the grid to auto-generate the columns for you. Instead, indicate that the auto-generation of the columns should be shut off, and then set the columns you wish to display. Then, when you set the ItemsSource, it should show only the items you wish to show.

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

Sidebar

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.