2013-09-24 2 views
0

인덱스를 사용하여 구조체를 반복하는 중입니다. 반성과는 별도로 쉬운 방법이 있습니까?VB에서 인덱스로 구조 반복 Iterating

코드 샘플;

For j As Integer = 0 To usedRange.ColumnCount - 1 
      ws.Cells(0, j).FillColor = Drawing.Color.DarkTurquoise 
Next 

의 내가 Drawing.Color (J) 같은

+1

'데이터 구조'가 아니라 Excel 워크 시트의 셀 집합입니다. 그것은 당신이 물어 보는 것이 분명하지 않기 때문에 당신의 질문을 다시 말해 줄 것입니다. – Robin

+0

. ws는 무엇을 나타 냅니까? 당신은 세포를 통해 잘 반복 될 수있는 것처럼 보입니다 (ws가 무엇인지에 따라 다름). – rheitzman

답변

0

당신이 색상 열거 찾고 있다면, 현재의 인덱스 값을 사용하여 각 셀에 다른 색상을 할당하려고한다고 가정 해 봅시다 :

' 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에 색상을 추가하는 해킹입니다. 이것이 합법적 인 코드인지는 모르지만 유틸리티로 사용합니다.

관련 문제