我是WPF的新手,我需要根据datagrid外部的按钮单击将dataobrid绑定到datagrid中。每次当我点击数据网格内的按钮组合框时都应该刷新。
我能够绑定源列组合框但是当我通过更改源文件单击“应用”按钮时它没有刷新,如上图所示。
我为此做的XAML代码是
<Grid Name="grdMappedTables" Margin="0,109,466,28" Background="LightGray">
<Grid.Resources>
<ObjectDataProvider x:Key="SourceDataProvider" ObjectType="{x:Type local:SourceTable}" MethodName="FillSourceTableCol" ></ObjectDataProvider>
</Grid.Resources>
<DataGrid Name="dgMappedTables" RenderOptions.ClearTypeHint="Enabled" TextOptions.TextFormattingMode="Display" CanUserAddRows="False"
SelectionUnit="FullRow" Style="{DynamicResource AzureDataGrid}" GridLinesVisibility="All" AutoGenerateColumns="False" BorderBrush="Black" BorderThickness="1">
<DataGrid.Columns>
<DataGridTextColumn Width="25" IsReadOnly="True" CanUserResize="False" >
</DataGridTextColumn>
<DataGridComboBoxColumn Header="Source" Width="200" CanUserResize="False" SelectedValueBinding="{Binding Path=column_id}" SelectedValuePath="column_id" DisplayMemberPath="column_name" ItemsSource="{Binding Source={StaticResource SourceDataProvider}}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="IsEditable" Value="False"></Setter>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridComboBoxColumn Header="Target" Width="200" CanUserResize="False" >
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
类后面的代码用于此
public class SourceTable
{
public DataView FillSourceTableCol()
{
DataTable dtSourceTable = new DataTable();
dtSourceTable = CommonDBClass.GetTable("select column_id, column_name from systabcol", strConnectionString);
return dtSourceTable.DefaultView;
}
}
单击“应用”按钮时,如何刷新组合框?