0

I have two datagrids, both with different purposes. I currently have a variable ObservableCollection<Competitor> Competitors as the datasource for the datagrids.

What I want to do, is use one datagrid to display the "competitors" in a leaderboard fashion, showing them and their times (this is a race-like leaderboard), with the fastest time being the winner. And, I wish for a second datagrid to show the users in a "points" leaderboard, showing the same users, with all their accumulated points over the past multiple competitions.

So, as you may know, setting the datasource for a datagrid allows the datagrid to automatically create columns for each variable in the class, as you will see below. However, within the class are variables I want in one column and not the other, visa versa. Such as, in the first datagrid, I want username, "VIs", "TimeFormated", and DQ, and in the second datagrid, I want username and Score.

Here is the full class I am using:

internal class Competitor
{
    public int Place { get; set; }
    public string Username { get; set; }
    public int VIStart { get; set; }
    public int VIEnd { get; set; }
    public int VIs { get { return VIEnd - VIStart; } }
    public double TimeInSeconds { get { return GetTime(); } }
    public string TimeFormated { get { return GetFormatTime(); } }
    public int Rerecords { get; set; }
    public bool DQ { get; set; }
    public string DQReason { get; set; }
    public double Score { get; set; }

    // More code here that is unimportant
}

So, I assume the best method for me to do is to custom set both datagrid's columns since they are so specific, however, I wish to know if there is a way to choose in-code which variables to display as column headers.

I am aware you can set [Browsable(false)], as per this question, however, from what I can tell, it is un-togglable.

Guidance and any tips and suggestions would be very appreciated. Thank you.

1 Answers1

1

Decorating your source properties with attributes is not going to solve your issue of displaying a particular property/column in one DataGrid but hide it in the other one.

The correct way to solve this would be to define the actual columns that you want to see explicitly, either programmatically in the code-behind of the view or in the XAML markup.

Auto generating columns may seem convenient but it's not very flexible.

mm8
  • 163,881
  • 10
  • 57
  • 88