This is a migrated thread and some comments may be shown as answers.

Option Strict On causes Late binding on DropDownList.DataSource

3 Answers 11 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Gone2TheDogs
Top achievements
Rank 1
Veteran
Gone2TheDogs asked on 23 Feb 2021, 08:57 PM

We are in the early process of converting from VB to C#. Before we convert, we are turning on Option Strict, one project at a time. I got the following Late Binding error on a RadDropDownList.DataSource. DataSource is deemed as an object (line 09 & 14), which is what is throwing the error, but not sure how to repair this. (error screenshot attached)

01.Public Shared Function IndexOfKeyOrValue(ByRef ddl As RadDropDownList, ByVal myString As String, ByVal LocateKey As Boolean) As Integer
02.    ' What I would like to do is pass any control to this function, see if it has a datasource and then do the rest.
03.    ' Use the TypeOf to determine the type of the control
04.    'AddEvent("IndexOfKeyOrValue Looking For: " & myString & " in " & ddl.Name)
05.    Try
06.        For xx As Integer = 0 To ddl.Items.Count
07.            'AddEvent(ddl.DataSource(xx).Key & "  " & ddl.DataSource(xx).Value)
08.            If LocateKey Then
09.                If ddl.DataSource(xx).Key = myString Then
10.                    'AddEvent("---- Index Found = " & xx)
11.                    Return xx
12.                End If
13.            Else
14.                If ddl.DataSource(xx).Value = myString Then
15.                    'AddEvent("---- Index Found = " & xx)
16.                    Return xx
17.                End If
18.            End If
19. 
20.        Next
21.    Catch ex As Exception
22.        ' AddEvent("---- NOT FOUND Index = -1")
23.        Return -1
24.    End Try
25.End Function  'IndexOfKeyOrValue

3 Answers, 1 is accepted

Sort by
0
Nadya
Telerik team
answered on 24 Feb 2021, 04:14 PM

Hello,

According to the provided picture, it seems that you receive a specific for VB Option Strict statement that restricts implicit data type conversions. This seems to be more like a general programming question this is why I made research in MSDN and StackOverFlow. The following threads might be useful in resolving this conflict:
https://docs.microsoft.com/en-us/dotnet/visual-basic/misc/bc30574 
https://stackoverflow.com/questions/12375405/option-strict-on-disallows-late-binding 
https://stackoverflow.com/questions/2454552/what-do-option-strict-and-option-explicit-do 
https://stackoverflow.com/questions/8283505/late-binding-and-option-strict 

Let me know if you have other questions.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Gone2TheDogs
Top achievements
Rank 1
Veteran
answered on 24 Feb 2021, 04:36 PM
Nadya. Thank-you for taking the time to list the links. I should have mentioned that I did research other sites for this type of issue as I'm converting a multitude of projects to C#, but not before I turn on Option Strict to reduce the number of issues during conversion. I guess my question is a bit out of range for this forum. I appreciate your taking the time. 
0
Nadya
Telerik team
answered on 25 Feb 2021, 02:56 PM

Hello,

Thank you for your understanding.

If you have questions that are not directly related to RadControls from the Telerik UI for WinForms suite, it is suitable to search in the relevant forums where similar questions might have been already discussed and would be helpful for you. In addition, I can suggest our free online C#/VB converter tool: https://converter.telerik.com/. Feel free to use it if it is suitable for you.

Should you have other questions about controls from Telerik UI for Winforms suite do not hesitate to contact us. 

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
DropDownList
Asked by
Gone2TheDogs
Top achievements
Rank 1
Veteran
Answers by
Nadya
Telerik team
Gone2TheDogs
Top achievements
Rank 1
Veteran
Share this question
or