@jrff9173
You probably went wrong where you are setting the HeaderText.
I'm not sure what you are trying to do but if the TextBox2.Text does not have any Text in it you could be referring to Null/Nothing which will throw a NullException error.
Or You may have gone wrong accessing your column....does the following column exist?
DataGridView1.C olumns(DataGrid View1.SelectedC olumns.ToString )
Actually it's more likely that this is your problem.
I'm pretty sure that DataGridView1.S electedColumns. ToString will return you "DataGridViewCo lumnCollection" .
In all likelihood you do not have a column named "DataGridViewCo lumnCollection" so when you try to set the HeaderText of this non-existent column you are getting a NullReferenceEx ception.
You probably want something like the following:
-
Dim newHeaderText As String = IIf(String.IsNullOrEmpty(TextBox2.Text), "", TextBox2.Text)
-
-
If DataGridView1.SelectedColumns IsNot Nothing AndAlso DataGridView1.SelectedColumns.Count > 0 Then
-
For Each selectedColumn As DataGridViewColumn In DataGridView1.SelectedColumns
-
selectedColumn.HeaderText = newHeaderText
-
Next
-
End If
-Frinny