CanUserAddRows binding error in themedDataGrid

Editors for WPF Forum

Posted 5 years ago by Sasha
Version: 14.1.0602
Avatar

Hi,

we deal with a strange behavior of a property CanUserAddRows during binding. Our goal is following behavior - when a cell value is 0, set CanUserAddRows to false, if any other value - to true. Here is xaml code :

<datagrid:ThemedDataGrid Grid.Row="2" Grid.Column="2" 
		 CanUserAddRows="{Binding CanAddRows}"
		 CanUserDeleteRows="True" 
		 AutoGenerateColumns="False" 
		 IsReadOnly="{Binding IsDatagridReadOnly}"
		 SelectedIndex="{Binding ModulBasisSelectedIndex}"
		 SelectedValue="{Binding ModulBasisSelectedValue}"
		 ItemsSource="{Binding ModulBasisCollection}" 
		 MaxHeight="125"   
		 SelectionUnit="FullRow" GridLinesVisibility="All" 
		 FrozenColumnCount="1"  
		 CellStyle="{StaticResource DataGridCellStyleKey}" 
		 Margin="20,3,3,3"
		 SelectionMode="Single">
		<i:Interaction.Triggers>
		    <i:EventTrigger EventName="CellEditEnding">
			<ei:CallMethodAction TargetObject="{Binding}" MethodName="OnModulBasisCellEditEnding"/>
		    </i:EventTrigger>
		</i:Interaction.Triggers>
		<datagrid:ThemedDataGrid.Columns>
			<datagrideditors:DataGridInt32Column Binding="{Binding BASIS, UpdateSourceTrigger=PropertyChanged}"
				                		 Minimum="0"/>
		</datagrid:ThemedDataGrid.Columns>
</datagrid:ThemedDataGrid>

 Here is property :

public bool CanAddRows
{
    get { return _canAddRows; }
    set
    {
        if(value == _canAddRows) return;
        _canAddRows = value;
        RaisePropertyChanged();
    }
}

 And we are changing this property on OnModulBasisCellEditEnding event :

 public void OnModulBasisCellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (e.EditAction != DataGridEditAction.Commit) return;

     var item = e.Row.Item as MODUL_BASIS;
     if (null == item) return;          

     if (0 == item.BASIS)
     {
         CanAddRows = false;               
     }
     else
     {
         CanAddRows = true;
     }
}

 When themedDatagrid is loaded, value is false by default. Then we add an item with value 1 and user is able to add new rows. If to enter value greater than 0, everything works fine. When 0 is entered, dataGrid changes value of canUserAddRows to false and user are not able to add rows. After that, value of themedDataGrid is always false and never changing back to true, no matter what value was entered.

How can I set it back to true?

Thank you

Comments (3)

Answer - Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Sasha,

For things like this that require some debugging, we really need a small sample project to debug.  Can you please put your sample together in a new simple sample project and email it to our support address?  Please rename the .zip file extension so it doesn't get spam blocked, and reference this thread.  Thanks!


Actipro Software Support

Posted 3 years ago by John Smith
Avatar

I have the same problem. I want to bind SelectionMode-Property of ThemedDataGrid to my property in ViewModel and it don't work.

My dataGrid:

                            <datagrid:ThemedDataGrid AutoGenerateColumns="False" CanUserAddRows="False" 
								 CanUserDeleteRows="False" ItemsSource="{Binding MessStellenColection}"  
                                 CellStyle="{StaticResource DataGridCellStyleKey}" Margin="3" 
                                 AutomationProperties.Name="MessStellenColectionDatagrid"                     
                                 SelectionMode="{Binding GrafikSelectionMode}" CanUserSortColumns="False" CanUserReorderColumns="False">

 my Property in ViewModel:

        public SelectionMode GrafikSelectionMode
        {
            get { return _selectionMode; }
            set
            {
                _selectionMode = value;
                RaisePropertyChanged();
            }
        }

 The SelectionMode is always "Extended".

 

Regards.

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The SelectionMode property is part of Microsoft's DataGrid control and appears to be a normal dependency property.  We don't alter or modify it in any way in our ThemedDataGrid control, which directly inherits the Microsoft DataGrid.  Perhaps you have a binding error?  Or if you are sure the binding is correct, you might want to follow up in Microsoft's support forums on this since it likely still happens if you swap to the normal native WPF DataGrid control.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.