[英]CheckListBox - Check items based on Array value - VB.NET
OK... After many many days of trying to figure it out, I have no option but to ask for help. 好的......经过许多天试图弄明白,我别无选择,只能寻求帮助。 I have Googled my little heart out and now it has led me here. 我用Google搜索了我的小心脏,现在它已经把我带到了这里。 PLEASE HELP. 请帮忙。
I get a string from my MySQL database server. 我从MySQL数据库服务器获取一个字符串。 I then split the string and put it into an array. 然后我拆分字符串并将其放入数组中。
Than I go through my checklistbox and see if any of the entries in there are equal to an array value. 我通过我的检查表,看看其中的任何条目是否等于数组值。 The problem is, it doesn't work and for the life of me I can't get it to work. 问题是,它不起作用,对我来说,我无法让它发挥作用。
This is somewhat of a template I have and if anyone can help me out with this problem, I would be more than thankful. 这有点像我的模板,如果有人可以帮我解决这个问题,我会非常感激。
Using connection As New MySqlConnection("datasource = " + IPADDRESS + "; username = '" + USERNAME + "'; password='" + PASSWORD + "' ; database = '" + DBASE + "'")
Using Command As New MySqlCommand("SELECT * FROM hazinc WHERE title = '" + ListBox1.Text + "'", connection)
connection.Open()
'Command.ExecuteReader()
Using reader As MySqlDataReader = Command.ExecuteReader()
While reader.Read()
'TextBox2.Text = reader("title")
STRINGRR = reader("involved")
End While
Dim NEWSTRINGRR As String() = STRINGRR.Split(",")
Dim CC As Integer
CC = 0
For Each X In NEWSTRINGRR
For I = 0 To clbEmployees.Items.Count - 1
Try
If clbEmployees.Items(I).ToString() = NEWSTRINGRR(I).ToString() Then
SetItemChecked(I)
End If
Catch ex As Exception
' MsgBox(ex.ToString)
End Try
Next
Next
End Using
connection.Close()
End Using
End Using
Anyone? 任何人? Please...? 请...?
I don't know for sure with so little code, but why are you using the same index for your If condition? 我不确定这么少的代码,但为什么你的If条件使用相同的索引? Then what good does X does? 那X有什么好处呢?
I think it should be like : 我认为应该是这样的:
For Each X In NEWSTRINGRR
For I = 0 To clbEmployees.Items.Count - 1
If clbEmployees.Items(I).ToString() = X.ToString() Then
SetItemChecked(I)
End If
Next
Next
CMIIW. CMIIW。
You do know STRINGRR is only going to have the value of the last row. 你知道STRINGRR只会有最后一行的值。 Add yes you need to post all your code. 添加是,您需要发布所有代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.