【发布时间】:2015-12-31 12:00:42
【问题描述】:
我想在ComboBox 中添加项目。我有两个array()。
Dim purpose_list() As String = {"ADMISSION", "1ST", "2ND", "3RD", "4TH", "5TH", "6TH", "7TH", "8TH", "9TH", "10TH", "11TH", "12TH"}
和
Dim find_purpose = GetListOfPurpose()
函数GetListOfPurpose()如下..
Private Function GetListOfPurpose() As List(Of String)
Dim Output As New List(Of String)()
Try
OpenConnection()
Dim st_roll As String = TbRoll.Text
Dim c_id As String = CmbCourse.SelectedValue
Dim cmd As New MySqlCommand
Dim qry As String = "SELECT purpose FROM fee_payment WHERE roll_no='" + st_roll + "' AND course='" + c_id + "'"
cmd.Connection = conn
cmd.CommandText = qry
Dim dr As MySqlDataReader = cmd.ExecuteReader
While dr.Read
Output.Add(dr("purpose").ToString())
End While
dr.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
CloseConnection()
End Try
Return Output
End Function
现在我想在find_purpose 中找到strings,如果存在,删除那些strings 并将其余的添加到ComboBox。
如果find_purpose 包含"1ST" 和"3RD",ComboBox 将添加其余项目
"ADMISSION", "2ND", "4TH", "5TH", "6TH", "7TH", "8TH", "9TH", "10TH", "11TH", "12TH"
我找到了This thread,但它在php。
VB.NET 应该怎么做?
【问题讨论】:
-
ComboBox1.Items.AddRange(purpose_list.Except(find_ purpose).ToArray())
-
@HansPassant 感谢您的评论。但是您的代码正在跳过
"2ND"。 -
LIST.FIND 可以为每个人循环提供帮助...试试这个:stackoverflow.com/questions/9854917/…