WPF GridControl:阻止在DataControlDetailDescriptor GridControl中选
本文关键字:GridControl DataControlDetailDescriptor 中选 WPF | 更新日期: 2023-09-27 18:24:13
我还没有找到任何令人满意的答案或解决方案。我有一个主细节网格(只有两个级别),只有单选。一些相关代码:
<dxg:GridControl AutoGenerateColumns="None" Name="gridControlMaster" AutoExpandAllGroups="True">
<dxg:GridControl.View>
<dxg:TableView ShowGroupPanel="False" />
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Entry.Date" Header="Entry date" Visible="True" AllowEditing="False" />
</dxg:GridControl.Columns>
<dxg:GridControl.DetailDescriptor>
<dxg:DataControlDetailDescriptor ItemsSourcePath="EntrySubList" ShowHeader="False">
<dxg:DataControlDetailDescriptor.DataControl>
<dxg:GridControl AutoGenerateColumns="None" AutoExpandAllGroups="True">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" ShowGroupPanel="False" ShowColumnHeaders="False" />
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Label" Header="Label" Visible="True" AllowEditing="False" />
<dxg:GridColumn FieldName="Value" Header="Value" Visible="True" AllowEditing="False" />
</dxg:GridControl.Columns>
</dxg:GridControl>
</dxg:DataControlDetailDescriptor.DataControl>
</dxg:DataControlDetailDescriptor>
</dxg:GridControl.DetailDescriptor>
</dxg:GridControl>
在某个时刻(比如在GridControl外部单击某个按钮),我需要主网格中当前选定的项,而不考虑细节网格中选定的子项!目前,如果我单击主网格中的某一行,然后单击详细信息网格中的某些行(与主网格中先前选择的行相比具有其他父项),CurrentItem或SelectedItem不是所需的项(它是主网格中最后一个选择的项,而它应该至少是当前高亮详细信息项的父项)。这可能会误导用户。
理想的解决方案是有某种"选择单元",在我的情况下是整个主项目,以及所有子项目(在详细的网格中)。因此,在网格中用户单击的任何项目上,无论是主项还是细节项,都会选择主项及其所有子项(高亮显示)。主网格的CurrentItem是当前选定的父项。
另一个可能的解决方案是只允许选择主网格项,并阻止在详细网格中进行选择(仅在详细网格控件上设置SelectionMode=none不能做到这一点!)。这种情况下的另一个好特性是,单击子项(尝试选择它)会在主网格中选择其父项。
如果需要任何进一步的信息,我会提供
谢谢你的回答。
据我所见,您描述的问题已经在DevExpress支持中心的主详细信息网格SelectedItem在单击详细信息行线程时出现意外行为。此线程中提供的解决方案-创建与主视图的选定项关联的附加属性,并在FocusedViewChanged事件处理程序中更新此属性。请看一下上面提到的讨论中附带的示例项目。我相信它会把你推向正确的方向。
谢谢你的指针,它真的帮助了我。我以前已经尝试过FocusedView属性,但显然不是正确的方式(可能在错误的网格级别上)。你的回答和链接帮助我解决了问题。
我做了这样的事:
<dxg:GridControl AutoGenerateColumns="None" Margin="0,36,1,0" Name="gridControlMaster" AutoExpandAllGroups="True">
<dxg:GridControl.View>
<dxg:TableView ShowGroupPanel="False" FocusedViewChanged="gridControlMaster_TableView_FocusedViewChanged" />
void gridControlMaster_TableView_FocusedViewChanged(object sender, FocusedViewChangedEventArgs e)
{
int rowHandle = ((GridControl)e.NewView.DataControl).GetMasterRowHandle();
if (GridControl.InvalidRowHandle == rowHandle) return;
gridControlMaster.SelectedItem = gridControlMaster.GetRow(rowHandle);
}
绑定到主GridControl的SelectedItem属性的某些测试TextBox显示在Detail GridControl中选择子项时所选的正确主记录。这对我来说已经足够了。