Home Forums WPF controls Xceed DataGrid for WPF display row numbers in column 0

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

    I am new to Xceed grid, and have spent the last 2 days trying to figure out how to do this very simple task.

    I have a WPF DataGridControl with 5 columns. I want the first column to be a read only column that just displays the row number.

    I found the Read-only property, so that is no problem, but I can’t figure out how to assign row numbers to those cells.

    Could you show me the xaml and the associated c# code to do this?

    Thanks!

    Imported from legacy forums. Posted by Shelley (had 8783 views)

    Xceed Support
    Member
    Post count: 5658

    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
    Source=”{Binding Source={x:Static Application.Current},
    Path=Orders}” />
    <Style x:Key=”itemIndexSelectorStyle”
    TargetType=”{x:Type xcdg:RowSelector}”>
    <Setter Property=”Content”
    Value=”{Binding RelativeSource={RelativeSource Self}, Path=ItemIndex}”/>
    </Style>

    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <Setter Property=”xcdg:RowSelectorPane.RowSelectorStyle”
    Value=”{StaticResource itemIndexSelectorStyle}” />
    </Style>

    </Grid.Resources>
    <xcdg:DataGridControl x:Name=”OrdersGrid”
    ItemsSource=”{Binding Source={StaticResource cvs_orders}}” />
    </Grid>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 293 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks! I didn’t realize that column 0 meant the gray row selector column , I had planned on making the row number its own column (1), but this works just as well.

    The only other thing is, how do I make the row numbers start at 1 instead of 0?

    Imported from legacy forums. Posted by Shelley (had 1009 views)

    User (Old forums)
    Member
    Post count: 23064

    I still haven’t been able to figure out how to start the row numbers at 1 instead of 0. How do I bind the row number to a function in my code behind .cs file that will increment each row number in column 0?

    Imported from legacy forums. Posted by Shelley (had 850 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    Just to clarify things up a little bit, the “Row Selector” is not a column, it is part of the DataGridControl’s ControlTemplate. Jenny gave you the code she had from one of her sample so you can either use it ‘as-is’ or transform it to your need.

    To add ‘+1’ to the value shown, you simply need to create a Converter for the binding to ItemIndex, which would look as follow:

    <Setter Property=”Content”
    Value=”{Binding RelativeSource={RelativeSource Self}, Path=ItemIndex, Converter={StaticResource myConverter}}”/>

    You can find an example on how to create a converter in this documentation topic:

    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Formatting%20a%20Cells%20Content.html

    Finally, if your goal is really to have a column displaying the ItemIndex, what you need to do is to Add a column in the “DataGridControl.Columns” collection and set its display member binding to the same as the one shown above, and set the column read-only.

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks, the converter was the missing link.

    Imported from legacy forums. Posted by Shelley (had 489 views)

    User (Old forums)
    Member
    Post count: 23064

    Row numbers were working just fine yesterday; but I have no idea why they aren’t showing up today even though I haven’t changed anything that would have effected it.

    This is my XAML;

    <c:ConvertRowToNumber x:Key=”RowToNumberConverter”/>

    <Style x:Key=”itemIndexSelectorStyle” TargetType=”{x:Type xcdg:RowSelector}”>
    <Setter Property=”Content”
    Value=”{Binding RelativeSource={RelativeSource Self}, Path=ItemIndex, Converter={StaticResource RowToNumberConverter}}”/>
    </Style>

    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <Setter Property=”xcdg:RowSelectorPane.RowSelectorStyle”
    Value=”{StaticResource itemIndexSelectorStyle}” />
    </Style>

    No row numbers are showing up in column 0 and
    the function ConvertRowToNumber in my code is also not being called.

    Do you see something wrong with this? What could have had an effect on this that it would no longer work.

    Thanks!

    Imported from legacy forums. Posted by Shelley (had 729 views)

    Xceed Support
    Member
    Post count: 5658

    If nothing has changed in your code since the last time it was working, I would suggest checking the version number of the assemblies to make sure that you are still using the latest one. Other than that, are any errors present in the output window?

    Imported from legacy forums. Posted by Jenny [Xceed] (had 4027 views)

    User (Old forums)
    Member
    Post count: 23064

    This works great with one issue. The item selector column is not resizable, so after about 999 the numbers are cut off. Is there an easy way to make that column resizable?

    Thanks,
    Tom

    Imported from legacy forums. Posted by tabraham (had 1613 views)

    User (Old forums)
    Member
    Post count: 23064

    There are no errors present in the Output Window. How does one check the version number of the assemblies?

    The only thing I changed in the code since then was to follow some other forum advice to alternate row colors for each DataRow. But I backed that out to see if it had any effect on column 0 numbers and it didn’t.

    Thanks for your help,
    Shelley

    Imported from legacy forums. Posted by Shelley (had 1539 views)

    Xceed Support
    Member
    Post count: 5658

    The RowSelectorPane is not resizable; however, you can provide it with a different width.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 346 views)

    Xceed Support
    Member
    Post count: 5658

    Select the assembly and check the version in the property grid.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 236 views)

    User (Old forums)
    Member
    Post count: 23064

    How do you provide a new width? I added this to the DataRow style above and it had no effect.

    <Setter Property=”xcdg:RowSelectorPane.Width” Value=”100″ />

    Thanks,
    Tom

    Imported from legacy forums. Posted by tabraham (had 382 views)

    User (Old forums)
    Member
    Post count: 23064

    Where do I find the assembly?

    Imported from legacy forums. Posted by Shelley (had 9021 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Update:

    It is important to change the Style that Jenny originally provided to use the “xcdg:RowSelector.RowSelectorStyle” property rather than the “xcdg:RowSelectorPane.RowSelectorStyle” property.

    Reference:
    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Xceed.Wpf.DataGrid.v4.0~Xceed.Wpf.DataGrid.RowSelector.html

    As for changing the width, this can be done through the RowSelectorPaneWidth property on the View.

    Reference:
    http://doc.xceedsoft.com/products/XceedWpfDataGrid/Xceed.Wpf.DataGrid.v4.0~Xceed.Wpf.DataGrid.Views.TableView~RowSelectorPaneWidth.html

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 2071 views)

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