表属性,datacolchanged事件:
Dim dr As DataRow
dr = DataTables("TypeA1").Find("[Qid] = '" & e.NewValue & "'")
If dr IsNot Nothing Then
Dim opt As String = dr("Opt") 'dr("Opt")是一组用|分割的字符串
Dim opts() As String
opts = opt.split("|") '分隔符,把单元格字符串变成数组
Dim cnt As Integer = opts.Length '数组个数
'根据数组个数,生成一个打乱顺序的集合,比如数组个数是5个,我需要生成一个集合{0,1,2,3,4},而且是打乱顺序的,再把这5个数组填入表格中
Dim ids1 As New List(Of Integer) '用于存储洗牌前的位置
Dim ids2 As New List(Of Integer) '用于存储洗牌后的位置
For i As Integer = 0 To cnt - 1 '准备初始的牌
ids1.add(i)
Next
For i As Integer = 0 To cnt - 1 '开始洗牌
Dim idx As Integer = ids1(rand.Next(0, ids1.count))
ids2.Add(idx)
ids1.Remove(idx)
Next
Dim Arys() As Integer
Arys = ids2.ToArray() '将集合转换为数组
Dim xxpx As String '新序
xxpx = String.Join(",", Arys)
e.DataRow("Xxpx") = xxpx
End If
这段码是不是可以简化呀 各位大神,我是见招拆招,谢谢麻烦各位大神了
内容一|内容二|内容三|内容四|内容五 | 2,1,3,0,4 |
[此贴子已经被作者于2023/12/11 20:04:04编辑过]