My issue: I have a datagridview and a DB file with ~100 columns and ~200 rows of data. This data is imported to the DGV onLoad(). Once i have the data i run a script that searchs a predefined(by the user) folder for text files. Each text file has anywhere between 2 and 100 lines of text each in the following format:
CRADEG DEGREE OF CRASH 1 Fatal 2 Injury 3 Non-casualty (towaway)
I can loop through the text file (ignoring the first line) and get each line of information and assign it a code (left column) and variable (right column).
What happens next is the script searchs for a column in the DGV with the same name as the text file. Once found, it loops through each row and looks for CODE1 (in my example CODE1 is '1') it then replaces the code in the DGV with the variable from the textfile (in my example VAR1 is 'Fatal').
However when this happens i get the following error:
Fatal is not a valid value for Double.
Obviously this means that the cell is set to hold a 'Double' data type. But i need to change it (and the rest of the column) to use the 'String' data type.
My code for those interested:
Dim headers As New List(Of String) For Each col As DataGridViewColumn In Me.DataGridView1.Columns headers.Add(col.HeaderText.ToString) Next DataGridView1.ReadOnly = False DataGridView1.AllowUserToAddRows = True DataGridView1.AllowUserToDeleteRows = True DataGridView1.AllowUserToOrderColumns = True Dim StrReader As StreamReader For i = 0 To headers.Count - 1 If File.Exists(txtFiles & headers.Item(i) & ".txt") Then StrReader = New StreamReader(txtFiles & headers.Item(i) & ".txt") Dim line As String Dim code As String Dim variable As String StrReader.ReadLine() Do line = StrReader.ReadLine() If line <> "" Then line.Trim() code = line.Split(vbTab)(0) variable = line.Split(vbTab)(1) code = code.Substring(7) MsgBox("C: " & code & vbNewLine & "V: " & variable) For j = 0 To DataGridView1.Rows.Count - 2 DataGridView1.CurrentCell = DataGridView1.Item(headers.Item(i), j) DataGridView1.CurrentCell.ValueType = GetType(String) If DataGridView1.CurrentCell.Value = code Then DataGridView1.CurrentCell.Value = variable End If MsgBox(DataGridView1.CurrentCell.Value) Next End If Loop Until line Is Nothing StrReader.Close() End If Next
Im not sure where to go from here and i've spent over an hour searching different ways to change the datatype, only to find infomation on swapping from a DGVTextBox to a DGVComboBox etc.
Any help is appreciated!!!