我有一个gridcontrol(GridControl1) 在gridcontrol里面,有两个网格视图(GridView1& GridView2) 我想获得GridView2中Selected行项的值并将其放在文本框中。 在GridView1上我可以使用此代码获取:
public static Size GetCurrentDisplaySize() {
var displayInformation = DisplayInformation.GetForCurrentView();
TypeInfo t = typeof(DisplayInformation).GetTypeInfo();
var props = t.DeclaredProperties.Where(x => x.Name.StartsWith("Screen") && x.Name.EndsWith("InRawPixels")).ToArray();
var w = props.Where(x => x.Name.Contains("Width")).First().GetValue(displayInformation);
var h = props.Where(x => x.Name.Contains("Height")).First().GetValue(displayInformation);
var size = new Size(System.Convert.ToDouble(w), System.Convert.ToDouble(h));
switch (displayInformation.CurrentOrientation) {
case DisplayOrientations.Landscape:
case DisplayOrientations.LandscapeFlipped:
size = new Size(Math.Max(size.Width, size.Height), Math.Min(size.Width, size.Height));
break;
case DisplayOrientations.Portrait:
case DisplayOrientations.PortraitFlipped:
size = new Size(Math.Min(size.Width, size.Height), Math.Max(size.Width, size.Height));
break;
}
return size;
}
但如果我在GridView2上选择任何一行,我什么也得不到。
有没有办法做到这一点。
答案 0 :(得分:1)
如果您使用了主要细节,请查看help article describing in detail
在你的GridControl中你必须处理Grid_MasterRowExpanded
,然后在程序上添加gridView.SelectionChanged
的句柄,这段代码会帮助你
Private Sub Grid_MasterRowExpanded(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs) Handles Grid.MasterRowExpanded
Dim view As GridView = sender
Dim detail As GridView = view.GetDetailView(e.RowHandle, e.RelationIndex)
detail.OptionsSelection.MultiSelect = True
If e.RowHandle = 0 Or e.RowHandle = 1 Then
AddHandler detail.SelectionChanged, AddressOf detail_SelectionChanged
End If
End Sub
Private Sub detail_SelectionChanged(ByVal sender As System.Object, ByVal e As DevExpress.Data.SelectionChangedEventArgs)
viewSelected = sender
Dim ro As DataRowView = viewSelected.GetFocusedRow
txtEmpId.Text = ro.Item("colEmp_Id")
End Sub