Používam foreach, aby som sa dostal do mriežky podľa stĺpcova pri opakovaní do jedného stĺpca musím vykonať overenie a opakovať do nasledujúceho viditeľného stĺpca, čo je overenie a resetovanie obrazu bunky v stĺpci.
// Code
For Each col In Me.TransactionsGrid.Rows.Band.Columns
If (col.Hidden = False) Then
"Get the first cell of the first column in the grid
cell= row.Cells(col.Index)
"Set the cell image
cell.Appearance.Image = My.Resources.Tran_comment_161
cell.Appearance.ImageHAlign = HAlign.Right
cell.Appearance.ImageVAlign = VAlign.Top
"Loop in to the next visible column and reset the image of the cell
//Code here
cell= row.Cells(UltraGridColumn.Index + 1)
"Reset the cell image
cell.Appearance.ResetImage()
Exit For
End If
Next
Ako to môžem dosiahnuť?
odpovede:
0 pre odpoveď č. 1Ak predpokladáme, že ActiveRow je riadok, ktorý chcete aktualizovať tento kód, nastaví váš obrázok v prvej bunke ActiveRow, ktorá nie je skrytá.
For Each col In Me.TransactionsGrid.ActiveRow.Band.Columns
UltraGridCell cell= row.Cells(col)
If (col.Hidden = True) Then
cell.Appearance.ResetImage();
else
cell.Appearance.Image = My.Resources.Tran_comment_161
cell.Appearance.ImageHAlign = HAlign.Right
cell.Appearance.ImageVAlign = VAlign.Top
Exit For
End If
Next
Slučku môžete tiež ovládať pomocou štandardu pre ... next a indexer
For x = 0 To Me.TransactionsGrid.ActiveRow.Band.Columns.Count - 1
UltraGridColumn col = Me.TransactionsGrid.ActiveRow.Band.Columns(x)
UltraGridCell cell= row.Cells(col)
If (col.Hidden = True) Then
cell.Appearance.ResetImage();
else
cell.Appearance.Image = My.Resources.Tran_comment_161
cell.Appearance.ImageHAlign = HAlign.Right
cell.Appearance.ImageVAlign = VAlign.Top
Exit For
End If
Next
Výhodou tohto druhého prístupu je zmena úvodného indexu v kolekcii stĺpcov (čiara niečo for x = 1 to Me.TransactionsGrid.ActiveRow.Band.Columns.Count - 1
)