Added RadCheckedListBox control on form, but null in code when I try to access it

1 Answer 144 Views
CheckedListBox
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Gone2TheDogs asked on 14 Jul 2021, 08:35 PM | edited on 14 Jul 2021, 10:59 PM

SOLVED:  InitializeComponent() wasn't being called. Thought this was automatic?

I would have deleted this post, but there is no option.

 

I dragged the RadCheckedListBox to the form. But when I try to add data to the Item property, I get an exception because the control is null. I thought that like other controls, the RadCheckedListBox methods and properties could be accessed without having to be instantiated first. The instantiation is in Private Sub InitializeComponent() :

Me.cklstSuppressedTickets = New Telerik.WinControls.UI.RadCheckedListBox()
CType(Me.cklstSuppressedTickets,System.ComponentModel.ISupportInitialize).BeginInit
Me.grpSuppressedTickets.Controls.Add(Me.cklstSuppressedTickets)
Me.cklstSuppressedTickets.Columns.AddRange(New Telerik.WinControls.UI.ListViewDetailColumn() {ListViewDetailColumn1})
Me.cklstSuppressedTickets.Location = New System.Drawing.Point(78, 61)
Me.cklstSuppressedTickets.Name = "cklstSuppressedTickets"
Me.cklstSuppressedTickets.Size = New System.Drawing.Size(290, 357)
Me.cklstSuppressedTickets.TabIndex = 0

 

cklstSuppressedTickets is the RadCheckedListBox that I added to the form using the designer. When I highlight the control in code during debug, it shows cklstSuppressedTickets as 'Nothing'.

	Private Sub LoadList()
		Dim tkt As KeyValuePair(Of String, string)
		For each tkt In dctTickets
			cklstSuppressedTickets.Items.Add(tkt.Key & "  -  " & tkt.Value)
		Next
	End Sub

 

 

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 15 Jul 2021, 11:40 AM

Hi, Bob,

I am glad that you managed to find what was causing the problem on your form and now you can add items to the RadCheckedListBox

InitializeComponent() method in Visual Studio.NET C# or VB.NET is a method that is automatically created and managed by Windows Forms designer and it defines everything you see on the form. When we drag controls to the Form in Visual Studio, behind the scenes, Visual Studio adds code to the InitializeComponent method, which should be called in the Form constructor.

If you have any further difficulties do not hesitate to contact me.

Regards,
Nadya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
CheckedListBox
Asked by
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or