Vb.net bindingsource.filter 来自字符串列表

Vb.net bindingsource.filter from a list of strings

我在 windows.form 中有一个组合框和一个数据网格视图, 我使用按钮在 datagridview 中添加行并从组合框中获取值(字符串),如果我双击 datagridview 的行,我将删除该行。

当我添加行时,我想 hide/disable/remove 组合框值,当我删除行时,我想在组合框中恢复它。

组合框值是从数据集源绑定的,组合框是下拉列表样式。

到目前为止,我尝试了一些方法,但这是我认为更好的方法,我现在所在的位置:

Dim filterList As List(Of String) = New List(Of String)

Private Sub filterListAdd()

        Dim dgResult As String
        filterList .Clear() 'Clear the list so no duplicates

        For i As Integer = 0 To combobox.Items.Count - 1
            Dim a As String = combobox.GetItemText(combobox.Items(i))

            For row As Integer = 0 To Dgview.RowCount - 1
                For col As Integer = 0 To Dgview.ColumnCount - 1
                Next
                Surname = Dgview.Rows(row).Cells(0).Value.ToString
                If dgResult = a Then 
                    filterList .Add(a) 'Add to list
                End If
            Next
        Next i

    End Sub   

Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click

Dgview.Rows.Add(combobox.Text)
filterListAdd()

'Here i want to bindingsource.filter = filterList 

End Sub

Private Sub Dgview_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Dgview.MouseDoubleClick

Dgview.Rows.Remove(Dgview.CurrentRow)

'I Guess here with the same way i filter it again

End Sub

任何帮助将不胜感激,在此先感谢。

帕诺斯

Public Class Form1

Dim clsItems As New ArrayList()

Private Sub RemoveComboItem()

Me.BindingSource.Position = Me.BindingSource.Find("1", Combobox.Text)
Dim 1Add As String = DirectCast(BindingSource.Current, DataRowView).Item("1").ToString
Dim 2Add As String = DirectCast(BindingSource.Current, DataRowView).Item("2").ToString
Dim 3Add As String = DirectCast(BindingSource.Current, DataRowView).Item("3").ToString

      clsItems.Add(New MyItem(1Add, 2Add, 3Add))

      BindingSource.RemoveCurrent()

  End Sub

Private Sub AddComboItem(dg As DataGridView) ' Because i have two datagridviews

      Dim 1 As String = dg.CurrentRow.Cells(0).Value.ToString()

      For i = 0 To clsItems.Count - 1
          If i <= clsItems.Count - 1 Then
              If 1 = clsItems(i).1 Then
                  Dim drNewRow As DataRow
                  drNewRow = DeeDataSet.Tables("Table").NewRow()
                  drNewRow("1") = clsItems(i).1
                  drNewRow("2") = clsItems(i).2
                  drNewRow("3") = clsItems(i).3
                  DeeDataSet.Tables("Table").Rows.Add(drNewRow)
                  clsItems.Remove(clsItems(i)) ' Remove it from array so no duplicates
              End If
          End If
      Next

  End Sub

Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click

RemoveComboItem()

End Sub

Private Sub Dgview_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Dgview.MouseDoubleClick

AddComboItem(Dgview)
Dgview.Rows.Remove(Dgview.CurrentRow)

End Sub

End class

Public Class MyItem

  Private m_s1 As String
  Private m_s2 As String
  Private m_s3 As String

  Public Sub New(1As String, 2 As String, 3 As String)

      M_sName = 1
      M_sSurname = 2
      M_sTitle = 3

  End Sub

  Public ReadOnly Property 1

      Get
          Return m_s1
      End Get

  End Property

  Public ReadOnly Property 2

      Get
          Return M_s2
      End Get

  End Property

  Public ReadOnly Property 3

      Get
          Return M_s3
      End Get

  End Property

End Class

在那种形式下,我不更新数据集,因为每次更改我都想以其他形式进行,所以当我从这里完成时,dataset.table 没有任何变化。