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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:49:20+00:00 2026-05-15T00:49:20+00:00

I have a collection of structures. The structure is just some strings. Example public

  • 0

I have a collection of structures. The structure is just some strings.
Example
public struct ReportLine
{
public string Name;
public string Address;
public string Phone;
…// about 10 other strings
}
I can’t change this part. What I want to do is display it in a simple grid or simlar in WPF. My only requirements are:
a) need column headers
b) rows must alternate in color
c) columns big enough to hold largest datum (which is not know until run time)

Can someone point me to an example to get me started? Is the GridView the way to go? Or DataGrid? Or perhaps just the grid?
I have the book Pro WPF in C# 2008 and it covers binding ListBox’s to collections, but the collections always seem to be collections of one field (ex. a collection of 40 names). Here I have a collection (an array in fact) of a structure.
How do I setup the databinding?

As you can see, I’m new to this and probably would most benefit from a reference to an article. I’ve found articles covering collections of 1 field, but no examples covering binding to an array of structures. Also, my intitial research indicates c) can’t be easily done, if you demand that the column is big enough for all the data in that column, not just the visible data.

Thanks,
dave

  • 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-15T00:49:20+00:00Added an answer on May 15, 2026 at 12:49 am

    All of the above can be done with the DataGrid and the ListView. Preferably in conjunction with DataTemplates.

    Its pretty simple, for example all requirements you listed can be achived with this single line:

    <DataGrid AutoGenerateColumns="True" 
              ItemsSource="{Binding Items}" 
              AlternatingRowBackground="Gray" />
    

    Where Items ist a property of type Item[] (an array of your structure instances).

    Note that the strings need to be exposed as propeties not as fields. If your structure does not meet this requirement you will have to introduce an adapter class or structure for this. Databinding generally does not work against fields.

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

Sidebar

Related Questions

I have a collection of objects to which I'd like to just add a
I have a collection of classes that inherit from an abstract class I created.
I have a collection of non-overlapping rectangles that cover an enclosing rectangle. What is
We have a collection of commercial MFC/C++ applications which we sell using Stingray Objective
I have a collection of classes that I want to serialize out to an
I have a collection of elements that I need to operate over, calling member
I have a collection of Boost unit tests I want to run as a
I have a collection of unmanaged dlls with a C# wrapper around them that
I have a collection of custom entity objects one property of which is an
currently i have jdbc code with the following basic stucture: get Connection (do the

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.