disabling checkbox in checkedlistbox

A

ameen.abdullah

Hi Guys,

I have a checked list box on my form.. the purpose of this checkbox is
to indicate that the option is enabled or disabled.. I just want to ask
if there is a way to disable these check boxes from being checked or
unchecked.. i want them to always show their default value which i have
fetched from a xml file.. and also i dont want the checked list box to
be disabled, as i want the user to select any item but not change the
checked state.

Thanks in advance guys..
 
I

Izzy

Are you familiar with Infragistics controls or do you use them?

If so, this is how I would do it:

I would use thier Ultra DataGrid and add 2 columns to it. One is the
description column and the other is the boolean column. Then load your
data and disable editing and set the CellClickActions property of the
grid to RowSelect.

This way they can view and select but not edit.

If you use Microsoft's grid, you can try this method but no guarantees.
 
A

ameen.abdullah

I m using microsoft's checkedlistbox control.. i has builtin checkbox
with every item and i jus wan to disable that checkbox..

cant use datagrids.. ill have to change the control over more then 10
places :(
 
A

ameen.abdullah

I m using microsoft's checkedlistbox control.. it has builtin checkbox
with every item and i jus wan to disable that checkbox..

cant use datagrids.. ill have to change the control over more then 10
places :(
 
I

Izzy

That can be accomplished like this:

Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e
As System.Windows.Forms.ItemCheckEventArgs) Handles
CheckedListBox1.ItemCheck
e.NewValue = e.CurrentValue
End Sub

In the "ItemCheck" Property of the check list box you just reset the
e.NewValue to the e.CurrentValue.

Hope this helps!
 
I

Izzy

Oops...I should test before I post, the e.NewValue = e.OldValue will
work but it loads the checked list box will everything unchecked. So to
work around that, do this:

Public Class Form1

Private FinishedLoading As Boolean = False

Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal
e As System.Windows.Forms.ItemCheckEventArgs) Handles
CheckedListBox1.ItemCheck
'Only perform if the form is finished loading.
If FinishedLoading Then e.NewValue = e.CurrentValue
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'Load data
CheckedListBox1.Items.Add("test1", True)
CheckedListBox1.Items.Add("test2", True)
CheckedListBox1.Items.Add("test3", False)
CheckedListBox1.Items.Add("test4", False)
CheckedListBox1.Items.Add("test5", True)
CheckedListBox1.Items.Add("test6", True)
CheckedListBox1.Items.Add("test7", False)

'Throw finished loading flag
FinishedLoading = True
End Sub
End Class


All this seems like such a hack to me, I'd just use a datagrid, but
since that's not an option......the above will work.
 
C

Cor Ligthert [MVP]

Ameen,

Is it not easier for your problem to use a listbox and put in that all the
possibilities while what is not possible is not in that listbox. (You can
even make one where you put something with a string concatenation in)

v Possible
- Not possible
v As well possible

The way you describe it, makes that you have if you have solved this problem
have to find how to find the checkbox that is selected while it is not
selected.

Just my thought,

Cor
 
A

ameen.abdullah

awesome man.. i worked perfectly :) thanks alot
Oops...I should test before I post, the e.NewValue = e.OldValue will
work but it loads the checked list box will everything unchecked. So to
work around that, do this:

Public Class Form1

Private FinishedLoading As Boolean = False

Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal
e As System.Windows.Forms.ItemCheckEventArgs) Handles
CheckedListBox1.ItemCheck
'Only perform if the form is finished loading.
If FinishedLoading Then e.NewValue = e.CurrentValue
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
'Load data
CheckedListBox1.Items.Add("test1", True)
CheckedListBox1.Items.Add("test2", True)
CheckedListBox1.Items.Add("test3", False)
CheckedListBox1.Items.Add("test4", False)
CheckedListBox1.Items.Add("test5", True)
CheckedListBox1.Items.Add("test6", True)
CheckedListBox1.Items.Add("test7", False)

'Throw finished loading flag
FinishedLoading = True
End Sub
End Class


All this seems like such a hack to me, I'd just use a datagrid, but
since that's not an option......the above will work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top