LookupGrid: Update Datasource when new value is added
This commit is contained in:
parent
2450977fc3
commit
11908ab246
@ -229,6 +229,16 @@ Public Class RepositoryItemLookupControl3
|
|||||||
If oResult = Windows.Forms.DialogResult.OK Then
|
If oResult = Windows.Forms.DialogResult.OK Then
|
||||||
Dim oValues = oForm.SelectedValues
|
Dim oValues = oForm.SelectedValues
|
||||||
UpdateSelectedValues(oValues)
|
UpdateSelectedValues(oValues)
|
||||||
|
|
||||||
|
If oForm.NewValues.Count > 0 AndAlso TypeOf DataSource Is DataTable Then
|
||||||
|
Dim oTable As DataTable = DirectCast(DataSource, DataTable)
|
||||||
|
|
||||||
|
For Each oValue In oForm.NewValues
|
||||||
|
Dim oRow = oTable.NewRow()
|
||||||
|
oRow.Item(0) = oValue
|
||||||
|
oTable.Rows.Add(oRow)
|
||||||
|
Next
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
End Using
|
End Using
|
||||||
End If
|
End If
|
||||||
|
|||||||
@ -9,6 +9,9 @@ Public Class frmLookupGrid
|
|||||||
Public Property PreventDuplicates As Boolean
|
Public Property PreventDuplicates As Boolean
|
||||||
Public Property DataSource As DataTable
|
Public Property DataSource As DataTable
|
||||||
Public Property SelectedValues As List(Of String)
|
Public Property SelectedValues As List(Of String)
|
||||||
|
Public Property NewValues As New HashSet(Of String)
|
||||||
|
|
||||||
|
Public Const COLUMN_SELECTED = "SELECTED"
|
||||||
|
|
||||||
Private _DataColumn As Integer
|
Private _DataColumn As Integer
|
||||||
Private _DataSourceTemp As DataTable
|
Private _DataSourceTemp As DataTable
|
||||||
@ -29,7 +32,7 @@ Public Class frmLookupGrid
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
If MultiSelect Then
|
If MultiSelect Then
|
||||||
If Not _DataSourceTemp.Columns.Contains("SELECTED") Then
|
If Not _DataSourceTemp.Columns.Contains(COLUMN_SELECTED) Then
|
||||||
Dim selectedColumn = New DataColumn() With {
|
Dim selectedColumn = New DataColumn() With {
|
||||||
.ColumnName = "SELECTED",
|
.ColumnName = "SELECTED",
|
||||||
.DataType = GetType(Boolean),
|
.DataType = GetType(Boolean),
|
||||||
@ -96,7 +99,7 @@ Public Class frmLookupGrid
|
|||||||
For oIndex = 0 To viewLookup.DataRowCount - 1
|
For oIndex = 0 To viewLookup.DataRowCount - 1
|
||||||
Dim oRow As DataRow = _View.GetDataRow(oIndex)
|
Dim oRow As DataRow = _View.GetDataRow(oIndex)
|
||||||
Dim oSelected As Boolean = oRow.Item(0)
|
Dim oSelected As Boolean = oRow.Item(0)
|
||||||
Dim oValue As Object = oRow.Item(1)
|
Dim oValue As Object = GetValueFromRow(oRow)
|
||||||
|
|
||||||
If oSelected Then
|
If oSelected Then
|
||||||
oValues.Add(oValue)
|
oValues.Add(oValue)
|
||||||
@ -115,7 +118,7 @@ Public Class frmLookupGrid
|
|||||||
Dim oValues As New List(Of String)
|
Dim oValues As New List(Of String)
|
||||||
|
|
||||||
If oRow IsNot Nothing Then
|
If oRow IsNot Nothing Then
|
||||||
Dim oValue = oRow.Item(0)
|
Dim oValue = GetValueFromRow(oRow)
|
||||||
oValues.Add(oValue)
|
oValues.Add(oValue)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@ -123,6 +126,13 @@ Public Class frmLookupGrid
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Function GetValueFromRow(pRow As DataRow) As String
|
||||||
|
If MultiSelect Then
|
||||||
|
Return pRow.Item(1)
|
||||||
|
Else
|
||||||
|
Return pRow.Item(0)
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
Private Sub SyncItemsWithView(view As GridView)
|
Private Sub SyncItemsWithView(view As GridView)
|
||||||
' Wenn Vorbelegungen existieren, werden diese angehakt
|
' Wenn Vorbelegungen existieren, werden diese angehakt
|
||||||
@ -145,8 +155,6 @@ Public Class frmLookupGrid
|
|||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|
||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
@ -235,9 +243,15 @@ Public Class frmLookupGrid
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub viewLookup_ValidateRow(sender As Object, e As ValidateRowEventArgs) Handles viewLookup.ValidateRow
|
Private Sub viewLookup_ValidateRow(sender As Object, e As ValidateRowEventArgs) Handles viewLookup.ValidateRow
|
||||||
If MultiSelect And e.RowHandle = GridControl.NewItemRowHandle Then
|
If e.RowHandle = GridControl.NewItemRowHandle Then
|
||||||
Dim oRow As DataRowView = viewLookup.GetRow(e.RowHandle)
|
Dim oRowView As DataRowView = viewLookup.GetRow(e.RowHandle)
|
||||||
oRow.Row.Item("SELECTED") = True
|
Dim oValue = GetValueFromRow(oRowView.Row)
|
||||||
|
NewValues.Add(oValue)
|
||||||
|
|
||||||
|
' Automatically select newly added row when MultiSelect is enabled
|
||||||
|
If MultiSelect Then
|
||||||
|
oRowView.Row.Item(COLUMN_SELECTED) = True
|
||||||
|
End If
|
||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
Loading…
x
Reference in New Issue
Block a user