I started a project with Options Strict Off and decided to turn it on after reading about it. I got the error regarding late binding being disallowed. I have checked some books, online help and several postings on this site about binding. I basically understand the difference between early and late binding, but I don't know how to fix my code to comply with Options Strick On.
Here's the code. It is in a private sub for a button click. The underlined code is what causes the error:
dim ID as String
ID = Me.CaseNumDataGridView.SelectedRows.Item(0).DataBoundItem("CASENUM")CASENUM is a text field. The DataGridView was created through drag-and-drop in the VB editor.
Thanks.

Understanding late binding
bangaram
I've found your error. You want to get the value stored in the CASENUM column of the first row in your collection. What you want to do is:
ID = CaseNumDataGridView.SelectedRows(0).Cells("CASENUM").Value
This code should work without a cast. If not add the directcast to it
ID=DirectCast( CaseNumDataGridView.SelectedRows(0).Cells("CASENUM").Value, String)
The reason you can leave out the Item property on SelectedRows and Cells is that Item is a default property meaning it can be accessed as if it were an array (or dictionary in the case of Cells).
To take this further you will probably want to iterate over each row in Selected rows so you can say
For Each tmpRow as DataGridViewRow in CaseNumDataGridView.SelectedRows
Next
Dan Moreira
I tried both CType and DirectCast with not luck - same error on same part of code. I tried this:
ID = Me.CaseNumDataGridView.SelectedRows.Item(0).DataBoundItem.ToString("CASENUM")
I got an error highlighting CASENUM and saying Options Strict disallows implicit conversion from 'String' to 'Integer'. There are not integer fields or variables here.
What next
MannuBhai
Option Strict also prevents implicit conversion i.e. converting from one datatype to another.
So, to fix your code:
dim ID as String
ID = ctype(Me.CaseNumDataGridView.SelectedRows.Item(0).DataBoundItem("CASENUM"), string)
or do a .ToString()
Zoop
Even though you know that CASENUM is a text field, the compiler has no way to predetermine this fact. Hence it would have to use late binding to do so.
In order to enable your code to work in this case you have to use the DirectCast keyword to tell the compiler that you know (or assume) that the object is indeed a string.
ID = DirectCast(CaseNumDataGridView.SelectedRows.Item(0).DataBoundItem("CASENUM"), String)
If for some reason that field does not turn out to be a string, the DirectCast call will through an InvalidCastException. You might want to surround this in a Try...Catch block and handle it.
Shahedul Huq Khandkar