如何解决选择更改后的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都会更新 自动(您可以看到价格已更新)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。