对于我的问题,我没有找到任何令人满意的答案或解决办法。我有一个主细节网格(仅2层),单一选择。一些相关守则:
<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是当前选择的父项。
另一种可能的解决方案是只允许选择主网格项,并防止详细网格中的选择(仅在细节GridControl上设置GridControl= none不会这样做!)在这种情况下,另一个很好的特性是单击子项(尝试选择它)在主网格中选择其父项。
如果需要进一步的资料,我会提供。
谢谢你的回答。
发布于 2014-09-24 07:00:13
据我所见,您所描述的问题已经在DevExpress支持中心的当单击详细信息行时,主细节网格SelectedItem的行为出乎意料。线程上下文中讨论过了。此线程中提供的解决方案--创建与主视图的选定项关联的附加属性,并在FocusedViewChanged事件处理程序中更新此属性。请看一下上面提到的讨论所附的样本工程。我相信它会把你推向正确的方向。
发布于 2014-09-25 07:22:06
谢谢你的指针,它真的帮了我。我以前已经尝试过使用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);
}一些绑定到主TextBox的SelectedItem属性的测试GridControl显示了在选择详细的子项时所选择的正确的主记录。这对我来说已经够好了。
https://stackoverflow.com/questions/26009422
复制相似问题