Vb.net VB中带索引的结构迭代
我试图通过使用索引来迭代结构。除了反思,还有什么简单的方法吗 代码示例Vb.net VB中带索引的结构迭代,vb.net,data-structures,iteration,Vb.net,Data Structures,Iteration,我试图通过使用索引来迭代结构。除了反思,还有什么简单的方法吗 代码示例 For j As Integer = 0 To usedRange.ColumnCount - 1 ws.Cells(0, j).FillColor = Drawing.Color.DarkTurquoise Next 假设我尝试使用当前索引值为每个单元格指定不同的颜色,如Drawing.color(j)如果要枚举颜色: ' Get all the values from the Known
For j As Integer = 0 To usedRange.ColumnCount - 1
ws.Cells(0, j).FillColor = Drawing.Color.DarkTurquoise
Next
假设我尝试使用当前索引值为每个单元格指定不同的颜色,如Drawing.color(j)如果要枚举颜色:
' Get all the values from the KnownColor enumeration.
Dim colorsArray As System.Array = [Enum].GetValues(GetType(KnownColor))
Dim allColors(colorsArray.Length) As KnownColor
Array.Copy(colorsArray, allColors, colorsArray.Length - 1)
With dgvColors
.ReadOnly = True
.Columns.Add("ColorName", "ColorName")
For i = 0 To allColors.Length - 1
.Rows.Add(allColors(i).ToString)
.Rows(i).Cells(0).Style.BackColor = Color.FromKnownColor(allColors(i))
Next
.Columns("ColorName").Width = 500
.Rows.RemoveAt(.Rows.Count - 2) ' delete - bug in arrays
.Rows.RemoveAt(.Rows.Count - 2) ' delete - bug in arrays
.ClearSelection()
End With
这是一种向DataGridView添加颜色的技巧-不确定这是合法代码,我只是将其用作实用工具。这不是“数据结构”,而是Excel工作表中的一组单元格。如果你不清楚你在问什么的话,那你最好把问题改写一下。同上。ws代表什么?看起来您可能在单元格中进行了很好的迭代(取决于ws是什么)