选择更改后的WPF自定义组合框控件会更新数据,但不会更新UI数据网格,除非我按Enter或单击鼠标

问题描述

我有一个自定义的“组合框”控件,该控件在“数据网格”内部使用。每当触发selectionchanged事件时,我都会更新“数据网格”的有界数据,但除非单击网格中的其他任何地方,否则它不会在UI中更新

    //Custom comboBox selection changed event code
        
            private void PackIdCombo_SelectionChanged(object sender,SelectionChangedEventArgs e)
            {
                 // i am updating the dataset which in bounded to datagrid from the custom user control 
                 //dr row has the combo values and its updating the global 
                 //dataset which is bounded to datagrid in other forms some lines are removed intentionally

                        global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Pack_id"] = dr["pack_id"].ToString().Trim();   
                        global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["disc_amt"] = (Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Tot_amt"]) * Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["disc_per"])) / 100;
                        global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Net_amt"] = (Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Tot_amt"]) - Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["disc_amt"])) * global.curr_rate;
                        double tax_per = string.IsNullOrEmpty(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["tax_per"].ToString()) ? 0 : Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["tax_per"].ToString());
                        global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["tax_amt"] = Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Net_amt"]) * (tax_per / 100);
                        global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Net_amt"]= Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["Net_amt"]) + Convert.Todouble(global.globalDataSet.Tables["stock_chk"].Rows[global.Selectedindex]["tax_amt"]);
                    
            }

Datagrid视图的XML代码

 <GroupBox Header="Items Details" Height="251" Name="groupBox1" Width="Auto" HorizontalAlignment="Left"  VerticalAlignment="Top" >
                    <my:DataGrid x:Name="DG_INV" Height="220" Width="960" VerticalAlignment="Center" HorizontalAlignment="Center" AutoGenerateColumns="False"
                                 RowStyle="{StaticResource RowStyle}" 
                             Background="LightGray" RowBackground="LightYellow" ItemsSource="{Binding}"
                    AlternatingRowBackground="LightBlue"  ScrollViewer.CanContentScroll="True" 
                  BorderBrush="Gray" BorderThickness="2" TabIndex="31" KeyboardNavigation.TabNavigation="Local" 
                                FontSize="11" RowHeight="15" FontFamily="Arial" MinRowHeight="23"  FrozenColumnCount="1" SelectionMode="Extended" SelectionUnit="FullRow"  CanUserSortColumns="False" CellEditEnding="DG_INV_CellEditEnding" KeyDown="DG_INV_KeyDown" KeyUp="DG_INV_KeyUp" MouseDoubleClick="DG_INV_MouseDoubleClick" PreviewKeyDown="DG_INV_PreviewKeyDown" SelectionChanged="DG_INV_SelectionChanged" ToolTip="Click enter from Qty,Price,Packing or Amount fields to calculate Net Amount">
                      


                             <my:DataGridTemplateColumn Header="Pack" Width="50" >
                                <my:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=Pack_id}"  />
                                    </DataTemplate>
                                </my:DataGridTemplateColumn.CellTemplate>
                                <my:DataGridTemplateColumn.CellEditingTemplate >
                                    <DataTemplate>
                                <cc:PackIdDropdown x:Name="ucPackIdCombo"> </cc:PackIdDropdown>
                                    </DataTemplate>
                                </my:DataGridTemplateColumn.CellEditingTemplate>
                            </my:DataGridTemplateColumn>

Image1 =这是带有自定义comBox控件的红色标记的Datagrid视图

Image2 =现在我已经更改了组合项,我可以看到数据是 已更新但未更新用户界面

Image3 =但是,当我单击该组合之外的任何位置时,datagrid都会更新 自动(您可以看到价格已更新)

This is the Datagrid view with custom combox in red mark

Now i have changed the combo item and i can see the data is updated but not the UI

But when i click anywhere outside of this combo UI is updated automatically

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)