473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Checkedlistbox

How can I turn on and off what is selected? I have a checked listbox I want
Index 0 = "All" and each of the other nodes to be a number. If the user
selects all I want to uncheck all the other items and visa versa.

Here is what I have on the checked event. I can not get this to compile.

Thanks
/// <summary>

/// Event fires when user checks Item

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstIteration_ItemCheck(object sender,
System.Windows.Forms.ItemCheckEventArgs e)

{

if (e.Index == 0)

{

this.lstIteration.ItemCheck -= new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

this.lstIteration.ClearSelected();

this.lstIteration..Items[0].Checked =
System.Windows.Forms.CheckState.Checked; //Line fails on compile

this.lstIteration.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

}

else

{

this.lstIteration.ItemCheck -= new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

this.lstIteration.Items[0].Checked =
System.Windows.Forms.CheckState.Unchecked; //Line fails on compile

this.lstIteration.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

}

}

Nov 16 '05 #1
1 4515
I got it to work like this

if (e.Index == 0)

{

this.lstIteration.ItemCheck -= new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

this.lstIteration.ClearSelected();

e.NewValue =System.Windows.Forms.CheckState.Checked;

this.lstIteration.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

}

else

{

// First show the index and check state of all selected items.

foreach(int indexChecked in lstIteration.CheckedIndices)

{

if(indexChecked == 0 && lstIteration.GetItemCheckState(indexChecked) ==
System.Windows.Forms.CheckState.Checked)

{

this.lstIteration.ItemCheck -= new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

lstIteration.SetItemCheckState(indexChecked,
System.Windows.Forms.CheckState.Unchecked);

this.lstIteration.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

break;

}

}

}

"MFRASER" <mf*****@henwoodenergy.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
How can I turn on and off what is selected? I have a checked listbox I want Index 0 = "All" and each of the other nodes to be a number. If the user
selects all I want to uncheck all the other items and visa versa.

Here is what I have on the checked event. I can not get this to compile.

Thanks
/// <summary>

/// Event fires when user checks Item

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void lstIteration_ItemCheck(object sender,
System.Windows.Forms.ItemCheckEventArgs e)

{

if (e.Index == 0)

{

this.lstIteration.ItemCheck -= new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

this.lstIteration.ClearSelected();

this.lstIteration..Items[0].Checked =
System.Windows.Forms.CheckState.Checked; //Line fails on compile

this.lstIteration.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

}

else

{

this.lstIteration.ItemCheck -= new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

this.lstIteration.Items[0].Checked =
System.Windows.Forms.CheckState.Unchecked; //Line fails on compile

this.lstIteration.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.ls tIteration_ItemCheck);

}

}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt C. | last post by:
Does the CheckedListBox support DisplayMember/ValueMember? I have been trying to use these properties with the CheckedListBox and they are not working. I see from Google that databinding is not...
4
by: Reza | last post by:
Hi, I want to check one of the memebrs of a checkedListbox based on its value. I 'm getting a number(say 1355) from another control and based on that number I want to check an item which its...
1
by: xiuyu_0129 | last post by:
Hi All, How do I store a string value for an item in a CheckedListBox in Windows Form? For a web based application, CheckBoxList allowed us to store 2 string values for the item in it. How do...
4
by: Matthew | last post by:
Hi, I am using a checkedlistbox on a windows form and binding it to a collection of classes. clbAliases is the checkedlistbox control selectedplace is a class with property placealiases.This...
2
by: CC | last post by:
Hi, We are populating a CheckedListBox from a database. Based on a selection by the user, the CheckedListBox either contains ALL possible members of a set, or a subset of possible members. The...
8
by: Derek Martin | last post by:
Here is some code that I need help with please: Dim result As New ArrayList Try For i = 0 To objecttest1.PersonList.person_returnnumber - 1 result =...
2
by: Manuel Canas | last post by:
Hi there, I'm having this dilema with a checkedlistbox. I have an array of items in there, what I want to accomplish is the following; The user could check all the items in the...
0
by: Terry Olsen | last post by:
Dim dirs() as string = Directory.GetDirectories(MyPath) CheckedListBox.DataSource = dirs CheckedListBox.Update For I as Integer = 0 To CheckedListBox.Items.Count - 1...
5
by: mabond | last post by:
Hi Can't believe I've not been able to find the answer to this in the on-line help. I have a CheckedListBox which, via a timer control, is populated with the names of files in a network...
6
by: Steve Teeples | last post by:
Can someone show me an example of how to place a "CheckedListBox" property within a PropertyGrid? -- ----------- Thanks, Steve
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.