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

How to check checkbox programmatically

5 Answers 740 Views
CheckedListBox
This is a migrated thread and some comments may be shown as answers.
Alvin
Top achievements
Rank 1
Alvin asked on 09 Dec 2011, 12:23 AM
Hi,

Could you give me an example for how to check custom item checkBox programmatically.

Thanks.

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 12 Dec 2011, 05:46 PM
Hi Alvin,

Thank you for writing.

As far as I understand, you want to check the RadCheckBoxElement. To achieve this, you can use the following code:

radCheckBoxElement1.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On

In case that you want to check ListView item, you should set the ListViewDataItem CheckState property to On:
radListView1.Items[2].CheckState = Telerik.WinControls.Enumerations.ToggleState.On

If this is not the case, then please describe your case in greater detail.

I hope this helps.

All the best,
Peter
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Alvin
Top achievements
Rank 1
answered on 15 Dec 2011, 06:47 AM
Thanks for replying.

I think I need to provide more information. What I want to do is to create custom items in RadListView from a list of objects.

After I create the MyCustomVisualItem class (icon view),  I get my custom items created successfully and displayed in RadListView. A checkbox is showed with each custom item listed in RadListView. But how can I checked the checkbox programmatically right after the custom item iscreated.

The code like following does not work

        Me.RadListView1.DataSource = myObjectList

        For i = 0 To Me.RadListView1.Items.Count - 1
            Me.RadListView1.Items(i).CheckState = Telerik.WinControls.Enumerations.ToggleState.On
        Next

Another problem is every time I update the myObjectList and run Me.RadListView1.DataSource = myObjectList to re-create the custom items in RadListView again, the checkboxes that have been checked with cursor previously will be unchecked automatically. But CheckState of these checkboxes are still "On". Any solution for that?

Thanks
0
Ivan Todorov
Telerik team
answered on 19 Dec 2011, 12:41 PM
Hi Alvin,

The approach you have described in your last post should work correctly. This makes me think that there might be something wrong with your custom visual items. Therefore, I would kindly ask you to open a new support ticket and send me a sample project which demonstrates this scenario. This will let me investigate it and provide you a solution. Alternatively, you can post your full source code here on the forums.

Generally, as I mentioned in a previous thread of yours, RadListView uses virtualization mechanism which means that the visual items stand for displaying the logical ones. At run time, each visual item is being detached and attached to different logical items so the check state should be kept in the data items.

I am looking forward to hearing from you.

Greetings,
Ivan Todorov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Alvin
Top achievements
Rank 1
answered on 20 Dec 2011, 03:06 AM
Thanks for reply.

You are right, I double-checked my custom visual item class and found "MyBase.SynchronizeProperties()" was commented out in function SynchronizeProperties(). It works fine after I changed it back.

Thanks
0
Ivan Todorov
Telerik team
answered on 21 Dec 2011, 03:29 PM
Hello Alvin,

I am glad that you have managed to sort this out.

Should you need future help, do not hesitate to contact us.

Kind regards,
Ivan Todorov
the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
CheckedListBox
Asked by
Alvin
Top achievements
Rank 1
Answers by
Peter
Telerik team
Alvin
Top achievements
Rank 1
Ivan Todorov
Telerik team
Share this question
or