How to enable or disable a button per row based on the index of the row

Not Answered This post has 0 verified answers | 6 Replies | 3 Followers Thread's RSS feed.

Brian Bergstrom
Points 640
Replied On: Mon, Jul 20 2009 1:57 PM Reply

How would you enable or disable a button in a GridRow based on the row index.  I have a number of grids that have a minimum requirement, but the user would be able to delete rows if they are non required records.

  • Post Points: 20

All Replies

Replied On: Mon, Jul 20 2009 5:01 PM Reply

Hello bberstrom,

You can create a style for the CellValuePresenter and in set the Template property to contain a button. Then you can bind the button's IsEnabled property to the TemplatedParent's (CellValuePresenter) Record.Index. You will have to use a Converter to convert the appropriate int's to the appropriate booleans.

Hope that helps.

Sincerely,
Aaron Marisi
Principal Product Developer
Infragistics, Inc.

  • Post Points: 20
travich
Points 2,334
Replied On: Mon, Jul 20 2009 5:21 PM Reply

My question is very similiar:

On my binding I need to enable/disable button on a row based on a checkbox's value on the same row.  I don't fully understand what you've said, but I was hoping kind of an on row binding event where I could test this.  Right now it happens on the valuechanged event and works correctly.  However, on binding it's like that value changed is not called and so I think I have to find a way to do it per row...  I guess I could do it on grid_load event and loop through each datarecord but that doesn't seem very eligant.

  • Post Points: 20
John Doe
Points 69,426
Infragistics Employee
Replied On: Tue, Jul 21 2009 1:27 AM Reply

Here is a sample code snippet that does the trick:

<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="buttonCell">

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">

                            <Button MaxWidth="20" Content="EDIT"/>

                        </ControlTemplate>

                </Setter.Value>

            </Setter>

                <Style.Triggers>

                    <DataTrigger Binding="{Binding Path=Cells[0].Value}" Value="False">

                        <Setter Property="IsEnabled" Value="False"/>

                    </DataTrigger>

                </Style.Triggers>

            </Style>

,where the checkbox is in my first field.

Hope this helps

Sincerely,
Alex Fidanov
Developer Support Engineer
www.infragistics.com\support

  • Post Points: 20
travich
Points 2,334
Replied On: Tue, Jul 21 2009 12:14 PM Reply

I have spent all morning trying to get these triggers to work...  Any idea what I am doing wrong?

 

                                                        <igDataGrid:UnboundField Name="BuyOutEditButton" Label="B/O">
                                                            <igDataGrid:UnboundField.Settings>
                                                                <igDataGrid:FieldSettings LabelWidth="40" CellWidth="40" AllowEdit="True">
                                                                    <igDataGrid:FieldSettings.CellValuePresenterStyle>
                                                                        <Style TargetType="{x:Type igDataGrid:CellValuePresenter}">
                                                                            <Setter Property="Template">
                                                                                <Setter.Value>
                                                                                    <ControlTemplate TargetType="{x:Type igDataGrid:CellValuePresenter}">
                                                                                        <Button Name="cmdEditBuyout" MinWidth="20" MinHeight="5" Height="22" Click="cmdEditBuyout_Click" IsEnabled="False" >Edit</Button>
                                                                                    </ControlTemplate>
                                                                                </Setter.Value>
                                                                              
                                                                            </Setter>
                                                                            <Style.Triggers>
                                                                                <DataTrigger Binding="{Binding Path=IsCustom}" Value="false">
                                                                                    <Setter Property="IsEnabled" Value="false"/>
                                                                                </DataTrigger>
                                                                                <DataTrigger Binding="{Binding Path=IsCustom}" Value="true">
                                                                                    <Setter Property="IsEnabled" Value="true"/>
                                                                                </DataTrigger>
                                                                            </Style.Triggers>
                                                                        </Style>
                                                                    </igDataGrid:FieldSettings.CellValuePresenterStyle>
                                                                </igDataGrid:FieldSettings>
                                                            </igDataGrid:UnboundField.Settings>
                                                        </igDataGrid:UnboundField>

  • Post Points: 5
travich
Points 2,334
Replied On: Tue, Jul 21 2009 12:15 PM Reply

FYI, I also tried to bind by cell value.  IsCustom values are correct as far as I can tell.

  • Post Points: 20
John Doe
Points 69,426
Infragistics Employee
Replied On: Wed, Jul 22 2009 1:30 AM Reply

I think the problem has to be fixed with setting RelativeSource, but it depends.

Without setting the relative source, this binding will target the DataRecordPresenter and will not be able to find IsCustom there. IsCustom is a property of the underlying object, so you might want to try with the cells collection ( as the code snipper above) or with the DataItem property of the Record of the DataRecordPresenter.

If IsCustom property is displayed in the same cell, as the button, you have to set RelativeSource to Self.

I am attaching the sample project just in case.

Sincerely,
Alex Fidanov
Developer Support Engineer
www.infragistics.com\support

  • Post Points: 5
Page 1 of 1 (7 items) | RSS