我有三列的网格控件,其中一列是一个lookUpEdit控件。在单元格中,我显示其值成员,这很好。但我也希望将显示成员显示为页脚网格控件,如信息文本。
如果我在我的控件 RepositoryLookUpEdit 中选择不同的值,那么我想将其对应的文本值(displayMember)显示到网格控件的页脚。我的代码是这样的:
Dim edit As RepositoryItemLookUpEdit = New RepositoryItemLookUpEdit
edit.DataSource = ds.Tables(0)
edit.DisplayMember = ds.Tables(0).Columns("KONTOSIFRA").Caption.ToString
edit.ValueMember = ds.Tables(0).Columns("KONTOSIFRA").Caption.ToString
edit.SearchMode = SearchMode.AutoFilter
' ds.Tables(0).Columns("KONTONAZIV").Caption.ToString ' This is what I want to show (display member)
dgvControl.RepositoryItems.Add((edit))
With dgView
.Columns(1).Name = "KONTOSIFRA"
.Columns(1).FieldName = "KONTOSIFRA"
.Columns(1).Caption = "KONTO"
.Columns(1).ColumnEdit = edit
.Columns(1).DisplayFormat.FormatType = FormatType.Numeric
.Columns(1).DisplayFormat.FormatString = "n"
.Columns(1).OptionsColumn.AllowEdit = True
.Columns(1).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom
.Columns(1).SummaryItem.DisplayFormat = ' Here I need to insert display member...?
Dim test As System.Data.DataRowView
test = edit.Properties.GetRowByKeyValue(edit.EditValue)
.Columns(1).SummaryItem.DisplayFormat = test.Item(1).ToString ' This works for gridLookUpEdit control, but my control is RepositoryLookUpEdit. How do I the same thing, only for my control?
End With
答案 0 :(得分:0)
使用类似:
.Columns(1).SummaryItem.DisplayFormat = "MyCustValue"
由于您已将SummaryType
设置为Custom
,因此您需要处理CustomSummaryCalculate
事件。
在这种情况下,你这样做:
if (e.SummaryProcess == CustomSummaryProcess.Finalize) {
var item = e.Item as GridColumnSummaryItem;
if (item.FieldName == "KONTOSIFRA") {
e.TotalValue = "blahblah";
}
}
答案 1 :(得分:0)
您可以使用RepositoryItemLookUpEdit.GetDisplayValueByKeyValue
方法从已知的值成员中获取显示成员。你需要处理GridView.CustomSummaryCalculate
事件
这是一个例子:
Private values As List(Of String)
Private Sub dgView_CustomSummaryCalculate(sender As Object, e As CustomSummaryEventArgs) Handles gridView1.CustomSummaryCalculate
If Not e.IsTotalSummary Then
Exit Sub
End If
Const fieldName$ = "KONTOSIFRA"
Dim summaryItem As GridSummaryItem = TryCast(e.Item, GridSummaryItem)
If summaryItem Is Nothing AndAlso summaryItem.FieldName <> fieldName$ Then
Exit Sub
End If
Select Case e.SummaryProcess
Case CustomSummaryProcess.Start
values = New List(Of String)
Case CustomSummaryProcess.Calculate
Dim edit As RepositoryItemLookUpEdit = DirectCast(dgView.Columns(fieldName$).ColumnEdit, RepositoryItemLookUpEdit)
Dim value As Object = edit.GetDisplayValueByKeyValue(e.FieldValue)
If Not IsNothing(value) Then
values.Add(value)
End If
Case CustomSummaryProcess.Finalize
If values.Count > 0 Then
e.TotalValue = String.Join(", ", values.Distinct())
End If
End Select
End Sub