Hallo,
kämpfe mit dem DataGridView und darin eingebauten Comboboxen.
Combobox Ansicht soll anders sein, als wenn man auf die Combobox klickt und dann Einträge wählen kann.
(z.B Ansicht: a
Klick auf Combobox - Eintrag: a - alpha
b - beta)
Dazu muss die Itemsliste beim Combobox DropDown geändert werden; und beim DropDownClosed wiederum das AnsichtsdataTable angebunden werden. (denke ich)
Problem hierbei es würde theoretisch so funktionieren, jedoch kann ich jetzt keine Einträge mehr wählen.
Jetzt habe ich zwar Eventhandler b. Combobox DropDown/DropDownClosed erstellt, und der Text in den Items ändert sich - jedoch kann ich keine Auswahl mehr treffen d.h. beim Klick auf ein anderes Item wird dieses nicht übernommen.
Anbei der Code:
Private cboGrid As ComboBox
Private mDTcboFormat As New DataTable("Format")
'ComboBox Spalte im DataGrid wird erzeugt
Private Sub DataGrid_ComboBoxSpalten_erstellen()
Dim TBcol As New DataGridViewComboBoxColumn
With TBcol
.ValueMember = mDTcboFormat.Columns("Format").ColumnName
.DisplayMember = mDTcboFormat.Columns("FormatB").ColumnName
.DataSource = mDTcboFormat ' DataTable an die Combobox
' binden
End With
dg_mask.Columns.Add(TBcol)
End Sub
Private Sub createFeldFormat()
Dim i As Integer
Dim ItemsW() As String = {"a", "n", "d", " "}
Dim ItemNameW() As String = {"a - alpha", "d - digit", "n - number", " "}
mDTcboFormat.Columns.Add("Format", GetType(System.String))
mDTcboFormat.Columns.Add("FormatB", GetType(System.String))
For i = 1 To ItemsW.Count
mDTcboFormat.Rows.Add(mDTcboFormat.NewRow)
mDTcboFormat.Rows(i - 1)(0) = ItemsW(i - 1)
mDTcboFormat.Rows(i - 1)(1) = ItemNameW(i - 1)
Next
End Sub
Private Sub dg_mask_EditingControlShowing(....)
Dim cmb As DataGridViewComboBoxEditingControl = CType(e.Control, _
DataGridViewComboBoxEditingControl)
RemoveHandler cmb.DropDownClosed, New EventHandler(AddressOf _
ComboBox_DropDownClosed)
AddHandler cmb.DropDownClosed, New EventHandler(AddressOf _
ComboBox_DropDownClosed)
RemoveHandler cmb.DropDown, New EventHandler(AddressOf ComboBox_DropDown
AddHandler cmb.DropDown, New EventHandler(AddressOf ComboBox_DropDown)
If dg_mask.CurrentCellAddress.X = 6 Then
cboGrid = DirectCast(e.Control, ComboBox)
End If
End Sub
'Erstellte Eventhändler f. Combobox
Private Sub ComboBox_DropDown(ByVal sender As Object, ByVal e As _
System.EventArgs)
'Name des Feldes, dessen Wert in der Spalte/Zelle angezeigt wird.
cboGrid.DisplayMember = mDTcboFormat.Columns("FormatB").ColumnName
End Sub
Private Sub ComboBox_DropDownClosed(ByVal sender As Object, ByVal e As _
EventArgs)
cboGrid.DisplayMember = mDTcboFormat.Columns("Format").ColumnName
End SubWarum kann ich jetzt keine Auswahl mehr treffen?
Danke |