HELP!!
I have a dynamically created datagridview which is added to my form controla and repeatedly refreshed. The gridview has 3 sets of 8 columns but only displays a set of columns if the row count in each set is greeater then 0.
Initially the datagrodview was disabled as it was only intedned as a display tool, however, the users are now required to acknowledge an alram that goes of as row level should a certain criteria be met. As the dataGridView is refreshed every 9 minutes, so too is the alarm!
I need to be able to allow the user to click on any cell in columns 1, 9 or 17 so that I can turn the alarm off for a period of time, but I'm unable to get those columns to be accessible to the user and then monitor for a click on that cell!
My code is as below so any help or advice would be greatly appreaciated!
Many thanks in advance
Steve
I have a dynamically created datagridview which is added to my form controla and repeatedly refreshed. The gridview has 3 sets of 8 columns but only displays a set of columns if the row count in each set is greeater then 0.
Initially the datagrodview was disabled as it was only intedned as a display tool, however, the users are now required to acknowledge an alram that goes of as row level should a certain criteria be met. As the dataGridView is refreshed every 9 minutes, so too is the alarm!
I need to be able to allow the user to click on any cell in columns 1, 9 or 17 so that I can turn the alarm off for a period of time, but I'm unable to get those columns to be accessible to the user and then monitor for a click on that cell!
My code is as below so any help or advice would be greatly appreaciated!
Many thanks in advance
Steve
Code:
genGridView.RowCount = MaxRowCount
If ComputerCount Mod genGridView.RowCount > 0 Then
ColumnCount = (Int(ComputerCount / genGridView.RowCount) + 1) * 8
Else
ColumnCount = (ComputerCount / genGridView.RowCount) * 8
End If
ColumnSet = ColumnCount / 8
genGridView.ColumnCount = ColumnCount
genGridView.Size = New Size(GridWidth * ColumnCount, Int(genGridView.RowCount * ColumnWidth))
Me.Size = New Size(FormWidth * ColumnCount, Int((genGridView.RowCount + 0.7) * ColumnWidth))
genGridView.ColumnHeadersVisible = False
genGridView.RowHeadersVisible = False
'genGridView.Enabled = False ' Taken this out for click red face
genGridView.ReadOnly = True
For col As Integer = 0 To genGridView.ColumnCount - 1
' Set column widths
Dim column As DataGridViewColumn = genGridView.Columns(col)
If col = 0 Or col = 8 Or col = 16 Then
column.Width = 200
Else
If col = 7 Or col = 15 Or col = 23 Then
column.Width = 60
Else
column.Width = 35
End If
End If
Next
For rw As Integer = 0 To genGridView.RowCount - 1
Dim row As DataGridViewRow = genGridView.Rows(rw)
row.Height = RowHeight
Next
For row As Integer = 0 To genGridView.RowCount - 1
genGridView.Rows(row).Cells(0).Value = ComputerName(row)
genGridView.Rows(row).Cells(0).Style.BackColor = Color.DarkSlateGray
genGridView.Rows(row).Cells(0).Style.ForeColor = Color.White
genGridView.Rows(row).Cells(0).Style.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Bold)
If ComputerSensor(row) > MaxTemp Then
genGridView.Rows(row).Cells(0).Style.ForeColor = Color.Red
End If
If String.IsNullOrEmpty((ComputerName(row + genGridView.RowCount))) = False Then
genGridView.Rows(row).Cells(8).Value = ComputerName(row + genGridView.RowCount)
genGridView.Rows(row).Cells(8).Style.BackColor = Color.DarkSlateGray
genGridView.Rows(row).Cells(8).Style.ForeColor = Color.White
genGridView.Rows(row).Cells(8).Style.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Bold)
If ComputerSensor(row + genGridView.RowCount) > MaxTemp Then
genGridView.Rows(row).Cells(8).Style.ForeColor = Color.Red
End If
Else
genGridView.Rows(row).Cells(8).Style.BackColor = Color.DarkSlateGray
End If
If String.IsNullOrEmpty((ComputerName(row + genGridView.RowCount + genGridView.RowCount))) = False Then
genGridView.Rows(row).Cells(16).Value = ComputerName(row + genGridView.RowCount + genGridView.RowCount)
genGridView.Rows(row).Cells(16).Style.BackColor = Color.DarkSlateGray
genGridView.Rows(row).Cells(16).Style.ForeColor = Color.White
genGridView.Rows(row).Cells(16).Style.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Bold)
If ComputerSensor(row + genGridView.RowCount + genGridView.RowCount) > MaxTemp Then
genGridView.Rows(row).Cells(16).Style.ForeColor = Color.Red
End If
Else
If ColumnSet = 3 Then
genGridView.Rows(row).Cells(16).Style.BackColor = Color.DarkSlateGray
End If
End If
' Computer Up
genGridView.Rows(row).Cells(1).Dispose()
genGridView.Rows(row).Cells(1).Value = ""
genGridView.Rows(row).Cells(1) = New DataGridViewImageCell
genGridView.Rows(row).Cells(1).Style.BackColor = Color.DarkSlateGray
genGridView.Rows(row).Cells(1).Style.Alignment = DataGridViewContentAlignment.MiddleCenter
If ComputerUp(row) >= 500 Then
genGridView.Rows(row).Cells(1).Value = My.Resources.redface
My.Computer.Audio.Play(My.Resources.aoogah, AudioPlayMode.Background)
Else
genGridView.Rows(row).Cells(1).Value = My.Resources.greenface
End If
If String.IsNullOrEmpty((ComputerName(row + genGridView.RowCount))) = False Then
genGridView.Rows(row).Cells(9).Dispose()
genGridView.Rows(row).Cells(9).Value = ""
genGridView.Rows(row).Cells(9) = New DataGridViewImageCell
genGridView.Rows(row).Cells(9).Style.BackColor = Color.DarkSlateGray
genGridView.Rows(row).Cells(9).Style.Alignment = DataGridViewContentAlignment.MiddleCenter
If ComputerUp(row + genGridView.RowCount) >= 500 Then
genGridView.Rows(row).Cells(9).Value = My.Resources.redface
My.Computer.Audio.Play(My.Resources.aoogah, AudioPlayMode.Background)
Else
genGridView.Rows(row).Cells(9).Value = My.Resources.greenface
End If
Else
genGridView.Rows(row).Cells(9).Style.BackColor = Color.DarkSlateGray
End If
If String.IsNullOrEmpty((ComputerName(row + genGridView.RowCount + genGridView.RowCount))) = False Then
genGridView.Rows(row).Cells(17).Dispose()
genGridView.Rows(row).Cells(17).Value = ""
genGridView.Rows(row).Cells(17) = New DataGridViewImageCell
genGridView.Rows(row).Cells(17).Style.BackColor = Color.DarkSlateGray
genGridView.Rows(row).Cells(17).Style.Alignment = DataGridViewContentAlignment.MiddleCenter
If ComputerUp(row + genGridView.RowCount) >= 500 Then
genGridView.Rows(row).Cells(17).Value = My.Resources.redface
My.Computer.Audio.Play(My.Resources.aoogah, AudioPlayMode.Background)
Else
genGridView.Rows(row).Cells(17).Value = My.Resources.greenface
End If
Else
If ColumnSet = 3 Then
genGridView.Rows(row).Cells(17).Style.BackColor = Color.DarkSlateGray
End If
End If
Next
' Display the grid
Me.Controls.Remove(genGridView)
Me.Controls.Add(genGridView)
genGridView.ClearSelection()
genGridView.Refresh()