Home Forums WPF controls Xceed DataGrid for WPF Data Grid Capabilities

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21664 |

    Hi there,

    We are very excited about using your grid in our WPF application, especially for it’s inbuilt sorting and grouping functionality. Your XBAP demo is very impressive and a great way to showcase the capabilities of what your components can do.

    Onto my question – in one of the screens application we need a headered grid with both column and row headers, where each data item corresponds to a single cell rather than a single row. Picture an application where you wanted to display and edit the scores for all the fixtures in a football season. Typically you would place their names both across the top and down the left, and each cell would represent the score of when one team played another. See http://www.confguide.com/fixtureGrid.do?season=2005 for an example of the style of grid I am talking about.

    This brings about number of requirements, and I am wondering which are supported by the current grid implementation?

    1. Two way binding directly to a collection of “fixture” objects, where each fixture has a home and away team and some data to be displayed in the cell. With a normal WPF listview, we would have to create “fake” data items for the rows, and handle transforming back to our actual data models, which is not ideal at all.

    2. Cell selection – being able to select a single cell rather than an entire row. Ideally, when a cell is selected (or has the mouse over it) both the row and column can be styled in some way to indicate which home and away teams the fixture is for.

    3. Ability for column and row headers to remain fixed as the user scrolls around the grid (similar to “freeze cells” in Excel).

    4. Ability to select multiple cells (using the mouse and/or keyboard) and paste a single value from the clipboard to them all

    5. Ability to select a range of cells and copy them all to the clipboard, then paste them all to another selection of cells (similar to the way Excel’s range-based copy and pasting works)

    Thanks in advance for your help!

    Neil

    Imported from legacy forums. Posted by nmosafi (had 3673 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello Neil,

    1. This is an interesting scenario, and we will try to provide a good end-to-end solution (like some sort of PivotView, for example) in a future release. In the meantime, there are some ways to achieve what you want to do.

    For example, you could set the ItemsPanel of the DataGrid to a UniformGrid and manually define a single Column that uses a MultiBinding to represent the home:away scores:

    XAML
    —-

    <code>
    <Grid>

    <Grid.Resources>
    <local:ScoreConverter x:Key=”scoreConverter” />

    <ItemsPanelTemplate x:Key=”fixtureItemsPanelTemplate”>
    <UniformGrid HorizontalAlignment=”Left”
    VerticalAlignment=”Top”
    Columns=”3″ />
    </ItemsPanelTemplate>

    </Grid.Resources>

    <xcdg:DataGridControl ItemsSource=”{x:Static local:FixtureCollection.DummyFixtureCollection}”
    AutoCreateColumns=”False”
    ItemsPanel=”{StaticResource fixtureItemsPanelTemplate}”>

    <xcdg:DataGridControl.Columns>
    <xcdg:Column>
    <xcdg:Column.DisplayMemberBinding>
    <MultiBinding Converter=”{StaticResource scoreConverter}”>
    <Binding Path=”HomeScore” />
    <Binding Path=”AwayScore” />
    </MultiBinding>
    </xcdg:Column.DisplayMemberBinding>
    </xcdg:Column>
    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.View>
    <xcdg:TableView ShowRowSelectorPane=”False”>

    <xcdg:TableView.FixedHeaders>
    <xcdg:ClearHeadersFooters />
    </xcdg:TableView.FixedHeaders>

    </xcdg:TableView>
    </xcdg:DataGridControl.View>

    </xcdg:DataGridControl>
    </Grid>
    </code>

    CODE
    —-

    <code>
    public class Fixture : INotifyPropertyChanged
    {
    public Fixture()
    {
    }

    public Fixture( string homeTeam, string awayTeam, int homeScore, int awayScore )
    {
    m_homeTeam = homeTeam;
    m_awayTeam = awayTeam;
    m_homeScore = homeScore;
    m_awayScore = awayScore;
    }

    private string m_homeTeam = string.Empty;

    public string HomeTeam
    {
    get
    {
    return m_homeTeam;
    }
    set
    {
    if( m_homeTeam != value )
    {
    m_homeTeam = value;
    this.OnPropertyChanged( “HomeTeam” );
    }
    }
    }

    private string m_awayTeam = string.Empty;

    public string AwayTeam
    {
    get
    {
    return m_awayTeam;
    }
    set
    {
    if( m_awayTeam != value )
    {
    m_awayTeam = value;
    this.OnPropertyChanged( “AwayTeam” );
    }
    }
    }

    private int m_homeScore;

    public int HomeScore
    {
    get
    {
    return m_homeScore;
    }
    set
    {
    if( m_homeScore != value )
    {
    m_homeScore = value;
    this.OnPropertyChanged( “HomeScore” );
    }
    }
    }

    private int m_awayScore;

    public int AwayScore
    {
    get
    {
    return m_awayScore;
    }
    set
    {
    if( m_awayScore != value )
    {
    m_awayScore = value;
    this.OnPropertyChanged( “AwayScore” );
    }
    }
    }

    protected virtual void OnPropertyChanged( string propertyName )
    {
    if( this.PropertyChanged != null )
    {
    this.PropertyChanged( this, new PropertyChangedEventArgs( propertyName ) );
    }
    }

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion
    }

    public class FixtureCollection : ObservableCollection<Fixture>
    {
    private static FixtureCollection s_dummyFixtureCollection;

    public static FixtureCollection DummyFixtureCollection
    {
    get
    {
    if( s_dummyFixtureCollection == null )
    {
    FixtureCollection c = new FixtureCollection();

    c.Add( new Fixture( “H1”, “A1”, 1, 2 ) );
    c.Add( new Fixture( “H1”, “A2”, 3, 4 ) );
    c.Add( new Fixture( “H1”, “A3”, 5, 6 ) );

    c.Add( new Fixture( “H2”, “A1”, 21, 22 ) );
    c.Add( new Fixture( “H2”, “A2”, 23, 24 ) );
    c.Add( new Fixture( “H2”, “A3”, 25, 26 ) );

    c.Add( new Fixture( “H3”, “A1”, 31, 32 ) );
    c.Add( new Fixture( “H3”, “A2”, 33, 34 ) );
    c.Add( new Fixture( “H3”, “A3”, 35, 36 ) );

    s_dummyFixtureCollection = c;
    }

    return s_dummyFixtureCollection;
    }
    }
    }

    public class ScoreConverter : IMultiValueConverter
    {
    #region IMultiValueConverter Members

    public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture )
    {
    return string.Format( “{0}:{1}”, values[ 0 ], values[ 1 ] );
    }

    public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo c

    Imported from legacy forums. Posted by Pascal (had 602 views)

    User (Old forums)
    Member
    Post count: 23064

    It looks like the code tags messed up with the layout of the text of my previous post, so here is a repost without the code…

    Hello Neil,

    1. This is an interesting scenario, and we will try to provide a good end-to-end solution (like some sort of PivotView, for example) in a future release. In the meantime, there are some ways to achieve what you want to do.

    For example, you could set the ItemsPanel of the DataGrid to a UniformGrid and manually define a single Column that uses a MultiBinding to represent the home:away scores:

    [code removed for forum layout purposes]

    2. While we do not support selection for a range of cells (like you can do in Excel for example), you could use the CurrentCell to track which cell is currently focused and apply a style accordingly. For styling the Row, you can define a Trigger on the Row.IsCurrent property. For styling the Column, you can define a Trigger in the DataCell’s style like so:

    [code removed for forum layout purposes]

    (We will probably add a IsCurrent property on Column to remove the requirement for a MultiBinding to detect whether a Cell is part of the CurrentColumn.)

    3. This is a highly requested feature, so stay tuned!

    4-5. As I said in #2, we do not support selecting a range of cells right now. I’ve added it to our feature request list.

    Thanks for your precious feedback!

    Imported from legacy forums. Posted by Pascal (had 578 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the detailed reply Pascal, we will try that.

    Regards
    Neil

    Imported from legacy forums. Posted by nmosafi (had 3480 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     I tried implementing the example above, and I’m getting an error that I must indicate a field name for the column I’m defining:

    “A column must have a fieldname. Parameter name: item.”

    Have you encountered this before?  Any help would be greatly appreciated.

     Thanks,

    Jerry

    Imported from legacy forums. Posted by Jerry (had 338 views)

    Xceed Support
    Member
    Post count: 5658

    Make sure to specify a FieldName when creating a Column.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 368 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

     Thanks for your reply.  The example in question was showing how to multibind two fields into one column and didn’t specify a fieldname, which in normal columnar situations would point that particular column to a single field.  Would specifying a single fieldname in a multibinding situation invalidate the multibinding?  (That was my assumption, can go back and test to make sure.)  Just wanted to be clear what I was trying to accomplish.

     Thanks again,

     Jerry

    Imported from legacy forums. Posted by Jerry (had 366 views)

    User (Old forums)
    Member
    Post count: 23064

    Here’s what I found out.  Even though specifying a field name in a column points that column to a field (normal binding), specifying a field name when you’re trying to multibind that column will NOT affect the multibinding.

     SO, I’m happy to say the error message I received was correct (in a world where error messages aren’t always so helpful), AND that your encouragement to trust the error message was justified.  But please note that if you run the code included in the example above, you will get the “field name” error.

     Thanks again for your help.  I’m having a great time discovering what all I can do with the control.

     Have a great one,

     Jerry

    Imported from legacy forums. Posted by Jerry (had 503 views)

    Xceed Support
    Member
    Post count: 5658

    The code sample is indeed misleading… It was created for version 1.0 of the product, which did not enforce usage of the FieldName ( this “bug” was corrected in a later version ).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 1326 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.