W
wk89
Guest
Hello all,
This programs attempts to read a textfile, spilt the strings delimited by ';', and change the BG color of the DataGridView accordingly.
I have a conversion error when executing this code. But I'm not sure where the error lies.
Please assist.
Function loadCellColor()
Dim i As Integer = 0 'Counter for Rows
Dim ID As Integer 'Store row ID value
Dim colIndex As Integer 'Store Column
Dim colorString As String 'Store Color Code
Dim FileToString As String = "" 'grab 1 line from file
Dim split As String() 'divide line via ";" delimiter
Dim filePath As String = "..\..\..\config\cellColor.txt"
Dim filenum As Integer
filenum = FreeFile()
'Read from File
Try
FileOpen(filenum, filePath, OpenMode.Input)
'Read Line by Line
While Not EOF(filenum)
FileToString = LineInput(filenum)
split = Regex.Split(FileToString, ";")
ID = Convert.ToInt32(split(0)) 'Store row ID value
colIndex = Convert.ToInt32(split(1)) 'Store Column
colorString = split(2) 'Store Color Code
System.Windows.Forms.MessageBox.Show(ID.ToString & " Column= " & colIndex.ToString & " color=" & colorString)
For i = 0 To ProjectsDataGridView.RowCount - 1
'Look for Matching Row ID
If ProjectsDataGridView.Rows(i).Cells(0).Value = ID Then
'Highlight the Cell
ProjectsDataGridView.Rows(i).Cells(colIndex).Style.BackColor = Color.FromArgb(CInt(colorString))
'Found the Cell, break loop and read next line
Exit For
End If
Next
End While
FileClose(filenum)
Catch ex As Exception
MessageBox.Show("File Error Occurred!" + vbCrLf + ex.ToString)
End Try
Return Nothing
End Function
The textfile looks like this:
79;6;-16711808
Continue reading...
This programs attempts to read a textfile, spilt the strings delimited by ';', and change the BG color of the DataGridView accordingly.
I have a conversion error when executing this code. But I'm not sure where the error lies.
Please assist.
Function loadCellColor()
Dim i As Integer = 0 'Counter for Rows
Dim ID As Integer 'Store row ID value
Dim colIndex As Integer 'Store Column
Dim colorString As String 'Store Color Code
Dim FileToString As String = "" 'grab 1 line from file
Dim split As String() 'divide line via ";" delimiter
Dim filePath As String = "..\..\..\config\cellColor.txt"
Dim filenum As Integer
filenum = FreeFile()
'Read from File
Try
FileOpen(filenum, filePath, OpenMode.Input)
'Read Line by Line
While Not EOF(filenum)
FileToString = LineInput(filenum)
split = Regex.Split(FileToString, ";")
ID = Convert.ToInt32(split(0)) 'Store row ID value
colIndex = Convert.ToInt32(split(1)) 'Store Column
colorString = split(2) 'Store Color Code
System.Windows.Forms.MessageBox.Show(ID.ToString & " Column= " & colIndex.ToString & " color=" & colorString)
For i = 0 To ProjectsDataGridView.RowCount - 1
'Look for Matching Row ID
If ProjectsDataGridView.Rows(i).Cells(0).Value = ID Then
'Highlight the Cell
ProjectsDataGridView.Rows(i).Cells(colIndex).Style.BackColor = Color.FromArgb(CInt(colorString))
'Found the Cell, break loop and read next line
Exit For
End If
Next
End While
FileClose(filenum)
Catch ex As Exception
MessageBox.Show("File Error Occurred!" + vbCrLf + ex.ToString)
End Try
Return Nothing
End Function
The textfile looks like this:
79;6;-16711808
Continue reading...