Home > database >  Too many aurguments to public overloads submenu in vb.net combobox
Too many aurguments to public overloads submenu in vb.net combobox

Time:06-24

Too many aurguments to public overloads submenu in vb.net combobox error in Function in vb.net combobox

Public Function combo(strQuery As String) As List(Of ComboBox)
    Dim objlist As New List(Of ComboBox)
    con.Open()
    Dim dt As New DataTable
    For Each dr In ExecuteReader(strQuery).Rows
        objlist.Add(New ComboBox(Convert.ToInt32(dr.Item(0).ToString()), dr.Item(1).ToString()))
    Next
    con.Close()
    Return objlist
End Function

<Extension>

Public Function ExecuteReader(strQuery As String) As DataTable
    Dim dt As New DataTable
    If con.State = ConnectionState.Open Then con.Close()
    con.Open()
    cmd = New SqlCommand(strQuery, con)
    da = New SqlDataAdapter(cmd)
    da.Fill(dt)
    con.Close()
    Return dt
End Function

CodePudding user response:

The ComboBox constructor does not take any parameters. https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.-ctor?view=windowsdesktop-6.0

I think your function should read

Private Class ComboBoxItem
    Public Property Id As Integer
    Public Property Text As String
    Public Sub New(Id As Integer, Text As String)
        Me.Id = Id
        Me.Text = Text
    End Sub
End Class

Public Function GetPopulatedCombo(strQuery As String) As ComboBox
    Dim Combo As ComboBox = New ComboBox
    Combo.DisplayMember = "Text"
    Using DT = ExecuteReader(strQuery)    
        For Each dr In DT.Rows
            Combo.Items.Add(New ComboBoxItem(dr.Item(0),dr.Item(1))
        Next
    End Using
    Return Combo 
End Function
  • Related