3

I have a DataGrid and whose column are bound to ViewModel Decimal Properties.

Decimal Value are showned when a value is added from a ViewModel but when i edit the same cell and remove content and then add, the cell is not accepting .Period. How can i edit a cell then.

<DataGrid Name="dgSales" Height="300" Margin="0,3,0,0" IsSynchronizedWithCurrentItem="True" SelectedItem="{Binding SelectedItem,Converter={StaticResource ignoreNewItemPlaceHolderConverter}}" ItemsSource="{Binding StockList,UpdateSourceTrigger=PropertyChanged}" ToolTip="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}" GotKeyboardFocus="dgSales_GotKeyboardFocus" CurrentCellChanged="dgSales_CurrentCellChanged">
    <DataGrid.Columns>
        <DataGridTextColumn Header="S No." Width="SizeToCells" MinWidth="60" Binding="{Binding SNo}" IsReadOnly="True" />
        <DataGridTemplateColumn Header="Stock Name" Width="280">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                <TextBlock Text="{Binding StockName}"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <ComboBox Width="280" Name="cmbStock" ItemsSource="{Binding Path=Stocks}" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" ></ComboBox>
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn Header="Unit Price" Width="SizeToCells" MinWidth="80" Binding="{Binding UnitPrice,UpdateSourceTrigger=PropertyChanged}" />
        <DataGridTextColumn Header="Unit" Width="SizeToCells" MinWidth="80" Binding="{Binding Unit}" IsReadOnly="True"/>
    <DataGridTextColumn Header="Quantity" Width="SizeToCells" MinWidth="80" Binding="{Binding Quantity,UpdateSourceTrigger=PropertyChanged}" />
        <DataGridTextColumn Header="Discount" Width="SizeToCells" MinWidth="80" Binding="{Binding Discount,UpdateSourceTrigger=PropertyChanged}"/>
        <DataGridTextColumn Header="Amount" Width="SizeToCells" MinWidth="100" Binding="{Binding Amount,StringFormat=\{0:n2\}}" IsReadOnly="True" />
    </DataGrid.Columns>
</DataGrid>                

1 Answer 1

4

The issue may be that you are using UpdateSourceTrigger=PropertyChanged which re-evalutes the text on every keystroke, and a number that ends in a decimal point is invalid. Try removing the UpdateSourceTrigger setting (therefore reverting to the default - LostFocus)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.