Datagridviewcomboboxcolumn 让我生气
我有一个绑定到源的 wpf datagridview 源是从数据库手动填充的数据集
,有一个 datagridcomboboxcolumn
我已将列的项目源设置为数据集(DSGLAccounts.tables..etc), 将显示成员路径设置为列名“Account_ID”;
并成功显示账户列表 但是当我在运行时选择一个项目时,当我导航到另一个单元格时,该单元格不会保留它,并且
现在就消失了,我无法理解如何使所选索引等于某个值,具体取决于作为网格视图源的数据集(DSRegisters)
我需要知道如何设置选定的索引 我想我必须了解属性 (SelectedItemBinding/SelectedValueBinding/SelectedValuePath)
这是表单
这是我的愚蠢代码:)
<DataGrid Name="dgv_Accounts" Width="Auto" Height="Auto" AutoGenerateColumns="False" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HeadersVisibility="Column" CanUserReorderColumns="False" CanUserResizeColumns="False"
CanUserSortColumns="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Visible"
BorderBrush="Gray" BorderThickness="0" HorizontalGridLinesBrush="Gray" VerticalGridLinesBrush="Gray"
AreRowDetailsFrozen="False" CanUserResizeRows="False" RowDetailsVisibilityMode="Visible" RowHeight="20" SelectionMode="Extended"
FlowDirection="LeftToRight" GridLinesVisibility="All" UseLayoutRounding="True" EnableColumnVirtualization="True"
FontFamily="DFKai-SB" FontWeight="Bold" FontStyle="Normal" Grid.Row="5" CellEditEnding="dgv_Accounts_CellEditEnding" RowEditEnding="dgv_Accounts_RowEditEnding">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="GL Account" Width="*" >
</DataGridComboBoxColumn>
<DataGridTextColumn Header="Description" Width="*" Binding="{Binding Path=Transc_desc, Mode=TwoWay}"/>
<DataGridTextColumn Header="Debit" Width="*" Binding="{Binding Path=Debit}"/>
<DataGridTextColumn Header="Credit" Width="*" Binding="{Binding Path=Credit}"/>
<DataGridTextColumn Header="Job" Width="*"/>
</DataGrid.Columns>
</DataGrid>
这是 DSRegister 背后的代码
dgv_Accounts.ItemsSource = DSRegisters.Tables[0].DefaultView;
DataGridComboBoxColumn COL = ((DataGridComboBoxColumn)(dgv_Accounts.Columns[0]));
COL.ItemsSource = DSGLAccount.Tables[0].DefaultView;
COL.DisplayMemberPath = "Account_ID";
,
是一个数据集,包含应显示在数据网格上的记录 DSGLAccounts 是 datagridcombobox 应该绑定到的数据集,
当我在运行时时,正如我所说,当从组合框中选择一个值时,当我离开单元格时,它不会保留选择,就好像它是不可编辑的,
我不喜欢wpf,请需要帮助,如果有一个例子或类似的东西,那将会非常有帮助
i have a wpf datagridview that is bound to a source
the source is a dataset filled from the database manually
there's a datagridcomboboxcolumn
i've set the column's items source to the dataset (DSGLAccounts.tables..etc),
set the displaymemberpath to the column name "Account_ID";
and it's successfully displays the account list
but when i sellect an item at run time, the cell does not keep it when i navigates to another cell and just disappears
now i cannot understand how to make the sellected index equals some value depending on the dataset which is the source of the grid view (DSRegisters)
i need to know how to set the selected index
i think i have to know about the properties (SelectedItemBinding/SelectedValueBinding/SelectedValuePath)
Here's the form
here's my stupid code :)
<DataGrid Name="dgv_Accounts" Width="Auto" Height="Auto" AutoGenerateColumns="False" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" HeadersVisibility="Column" CanUserReorderColumns="False" CanUserResizeColumns="False"
CanUserSortColumns="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Visible"
BorderBrush="Gray" BorderThickness="0" HorizontalGridLinesBrush="Gray" VerticalGridLinesBrush="Gray"
AreRowDetailsFrozen="False" CanUserResizeRows="False" RowDetailsVisibilityMode="Visible" RowHeight="20" SelectionMode="Extended"
FlowDirection="LeftToRight" GridLinesVisibility="All" UseLayoutRounding="True" EnableColumnVirtualization="True"
FontFamily="DFKai-SB" FontWeight="Bold" FontStyle="Normal" Grid.Row="5" CellEditEnding="dgv_Accounts_CellEditEnding" RowEditEnding="dgv_Accounts_RowEditEnding">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="GL Account" Width="*" >
</DataGridComboBoxColumn>
<DataGridTextColumn Header="Description" Width="*" Binding="{Binding Path=Transc_desc, Mode=TwoWay}"/>
<DataGridTextColumn Header="Debit" Width="*" Binding="{Binding Path=Debit}"/>
<DataGridTextColumn Header="Credit" Width="*" Binding="{Binding Path=Credit}"/>
<DataGridTextColumn Header="Job" Width="*"/>
</DataGrid.Columns>
</DataGrid>
that's code behind
dgv_Accounts.ItemsSource = DSRegisters.Tables[0].DefaultView;
DataGridComboBoxColumn COL = ((DataGridComboBoxColumn)(dgv_Accounts.Columns[0]));
COL.ItemsSource = DSGLAccount.Tables[0].DefaultView;
COL.DisplayMemberPath = "Account_ID";
where
DSRegister is a dataset contains records that should be displayed on the datagrid
DSGLAccounts is the dataset to which the datagridcombobox should be bound
also when i at run time as i said, when select a value from the combobox, it does not keep sellection when i leave the cell , as if it's non editable
i'm noooob in wpf, need help please , if there's an example or something like this , it would be very helpful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保持选定值的解决方案 - 只需在后面的代码中添加类似的内容:
Solution for keeping selected value - just add something like this in code behind: