Home Forums WPF controls Xceed DataGrid for WPF Binding Data to Visibile Property

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

    Hello,

    I want to show or hide columns by binding thier visibility to a property. For example,

    My class looks something like:
    public class MyClass
    {
    public string MyColumn { get {…}}
    public bool ShowMyColumn { get {…}}
    }

    <xcdg:DataGridControl ItemsSource=”{Binding Path=Model.AllMyClassInstances}”>

    <xcdg:Column FieldName=”MyColumn” Title=”My Column” Visible=”{Binding Path=ShowMyColumn}”/>

    Thanks

    Imported from legacy forums. Posted by Murthy (had 3339 views)

    Xceed Support
    Member
    Post count: 5658

    You can specify the Source of the Binding applied to the Visible property of the Column as your MyClass instance for the column.

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

    User (Old forums)
    Member
    Post count: 23064

    Thank you Markus, but the thing is that the instance I want to bind to is one of the instances in the ItemsSource. So how can I synchronize the two sources.

    Here is what I mean:

    <xcdg:DataGridControl ItemsSource=”{Binding Path=Model.AllMyClassInstances}”>

    <xcdg:Column FieldName=”MyColumn” Title=”My Column” Visible=”{Binding Path=ShowMyColumn}”/>

    ShowMyColumn is another property from the ItemsSource Instance. In other words, MyClass has two properties: MyColumn & ShowMyColumn.

    Thanks again.

    Imported from legacy forums. Posted by Murthy (had 181 views)

    Xceed Support
    Member
    Post count: 5658

    Once again, if you create a column for a “specific” instance of your class instance… I don’t see why you wouldn’t be able to bind to it…

    Otherwise, you could also create an implicit style for all Cell types and create a trigger that would collapse cells if the “ShowMyColumn” is false.

    <code>
    <Style TargetType=”{x:Type xcdg:DataCell}”>
    <Style.Triggers>
    <DataTrigger Binding=”{Binding ShowMyColumn}” Value=”False”>
    <Setter Property=”Visibility” Value=”Collapsed”/>
    </DataTrigger>
    </Style.Triggers>
    </Style>
    </code>

    You would have to create one such trigger for all of your cell types (ColumnManagerCell, InsertionCell, DataCell, … ).

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks Marcus,

    I’ll follow up your styling suggestion. You know, I don’t think I understood your first suggestion.

    Are you sugessting that I do this:

    <xcdg:DataGridControl ItemsSource=”{Binding Path=Model.AllMyClassInstances}”>

    <xcdg:Column FieldName=”MyColumn” Title=”My Column” Visible=”{Binding Path=ShowMyColumn}”/>
    <xcdg:Column FieldName=”MyColumnVisible” Title=”MyColumnVisible”/>

    I’m not sure how that helps? How would I be able hide MyColumn when MyColumnVisible is set to false?

    Thanks a lot for you help.

    Regards.

    Imported from legacy forums. Posted by Murthy (had 4325 views)

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