Hi, I have this code which creates button in Cell with a image.
Private Sub GridControlCertificateManager_QueryCellInfo(sender As Object, e As GridQueryCellInfoEventArgs) Handles GridControlCertificateManager.QueryCellInfo
Select Case e.ColIndex
Case 1
e.Style.BackColor = Color.Azure
e.Style.ReadOnly = True
Case 5
If e.RowIndex <> 0 Then
e.Style.CellType = GridCellTypeName.Control
e.Style.Control = btnPasteSrNo
btnPasteSrNo.Name = "btnPasteSrNo"
btnPasteSrNo.FlatStyle = FlatStyle.Popup
btnPasteSrNo.TabStop = False
e.Style.CellTipText = "Click to Paste Serial Nos."
btnPasteSrNo.ImageList = m_clsImageList
btnPasteSrNo.ImageIndex = 1
End If
Case 6
If e.RowIndex <> 0 Then
'Creates the list.
Dim items As New StringCollection
items.AddRange(New String() {"Pass", "Fail"})
'Sets the style properties.
e.Style.CellType = "ComboBox"
e.Style.ChoiceList = items
If e.Style.CellValue.trim = "" Then
e.Style.CellValue = "Pass"
End If
'True droplist - no editing.
e.Style.DropDownStyle = GridDropDownStyle.Exclusive
End If
Case 10
If e.RowIndex <> 0 Then
e.Style.CellType = GridCellTypeName.Control
e.Style.Control = btnAddFile
btnAddFile.Name = "btnAddFile"
btnAddFile.FlatStyle = FlatStyle.Popup
btnAddFile.TabStop = False
btnAddFile.ImageList = m_clsImageList
e.Style.CellTipText = "Click to Add Certificates"
btnAddFile.Image = m_clsImageList.Images(0)
End If
End Select
End Sub
Everything is ok. Check code in RED Color; When I click this button it opens a dialogue box and allows to select a file. Then the Selected file path appears in the adjoining cell i.e., 9th cell and 10th cell is the button.
What I am trying to achieve is when the cell 9 is empty the button image should be the initial one (that is AddButtonIcon from ImageList index 0) and if some path is available in that cell then Image should be another one (that is RemoveFileIcon from ImageList index 2).
How do we achieve this it's easily done in VB control like below;
Private Sub dataGridViewInspectionReportCertificateDetails_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles dataGridViewInspectionReportCertificateDetails.CellFormatting
'e.Value = Global.ICCS.My.Resources.Resources._20removeFile
If e.RowIndex < 0 OrElse Not e.ColumnIndex = _
dataGridViewInspectionReportCertificateDetails.Columns("addNewUpdatedReport").Index Then Return
Select Case Trim(dataGridViewInspectionReportCertificateDetails.Rows(e.RowIndex).Cells("replaceReportPath").Value)
Case ""
e.Value = Global.ICCS.My.Resources.Resources._20add_file
Case Else
e.Value = Global.ICCS.My.Resources.Resources._20removeFile
End Select
End Sub