Click here to Skip to main content
13,770,697 members
   

C#

 
GeneralRe: Instantiating an array of objects Pin
crushinghellhammer29-Jul-04 10:32
membercrushinghellhammer29-Jul-04 10:32 
GeneralRe: Instantiating an array of objects Pin
Nick Parker29-Jul-04 11:11
protectorNick Parker29-Jul-04 11:11 
GeneralWM_PRINT for themed controls Pin
Mathew Hall29-Jul-04 7:31
memberMathew Hall29-Jul-04 7:31 
GeneralRe: WM_PRINT for themed controls Pin
Heath Stewart29-Jul-04 10:25
protectorHeath Stewart29-Jul-04 10:25 
GeneralCalculating Point locations in relation to Parent client area. Pin
Tristan Rhodes29-Jul-04 7:27
memberTristan Rhodes29-Jul-04 7:27 
GeneralRe: Calculating Point locations in relation to Parent client area. Pin
Nick Parker29-Jul-04 9:06
protectorNick Parker29-Jul-04 9:06 
GeneralRe: Calculating Point locations in relation to Parent client area. Pin
Anonymous30-Jul-04 14:42
memberAnonymous30-Jul-04 14:42 
GeneralCheckedListBox event handling strangeness Pin
James Kolpack29-Jul-04 6:32
memberJames Kolpack29-Jul-04 6:32 
Hi,

I want to update both the contents and the checked state of items in a CheckedListBox on the ItemCheck event. It turns out that when removing an item that occurs before the checked item (the one that is being processed), both this checked item and the one after it will appear to be checked after the event finishes. To illustrate, here is some code that first populates a CheckedListBox with a sequence of integers (named checkedListBox), and then when an item is checked, removes this item, and also checks the previous item if it was even, or the following item if it was odd.

private void checkedListBox_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
// get the currently checked index
int checkedItemIndex = (int)checkedListBox.Items[checkedListBox.SelectedIndex];
bool checkedEven = checkedItemIndex % 2 == 0 ? true : false;

// remove the event handler for now - it is triggered by SetItemCheckState
checkedListBox.ItemCheck -= new ItemCheckEventHandler(checkedListBox_ItemCheck);

// if it was an even number, check the previous index
// ie - checking 4 will result in 3 being checked
// else, check the following index
// ie - checking 5 will result in 6 being checked
if (checkedItemIndex > 1 && checkedEven)
checkedListBox.SetItemCheckState(checkedItemIndex - 1, CheckState.Checked);
else if (checkedItemIndex < checkedListBox.Items.Count - 1)
checkedListBox.SetItemCheckState(checkedItemIndex, CheckState.Checked);

checkedListBox.ItemCheck += new ItemCheckEventHandler(checkedListBox_ItemCheck);

// remove the currently clicked index
checkedListBox.Items.RemoveAt(checkedItemIndex);
}


// here is the code to populate the box
private void resetListBoxContents()
{
checkedListBox.Items.Clear();
for (int i=0; i < 20; i++)
checkedListBox.Items.Add(i);
}


As you see, when checking 9, 9 is removed and 10 is checked. But when 4 is checked and removed, 3 becomes checked, as it should be, but so is 5, which should not be.

Any help in this matter would be greatly appreciated. Thanks!
GeneralRe: CheckedListBox event handling strangeness Pin
Nick Parker29-Jul-04 9:01
protectorNick Parker29-Jul-04 9:01 
GeneralRe: CheckedListBox event handling strangeness Pin
James Kolpack29-Jul-04 9:31
memberJames Kolpack29-Jul-04 9:31 
GeneralRe: CheckedListBox event handling strangeness Pin
James Kolpack29-Jul-04 12:12
memberJames Kolpack29-Jul-04 12:12 
GeneralC# DataGrid - how to get the sort arrow in column header Pin
T J Manjaly29-Jul-04 6:03
sussT J Manjaly29-Jul-04 6:03 
GeneralColumn selection control needed Pin
Jan R Hansen29-Jul-04 5:38
memberJan R Hansen29-Jul-04 5:38 
GeneralRe: Column selection control needed Pin
billb211229-Jul-04 5:52
memberbillb211229-Jul-04 5:52 
GeneralRe: Column selection control needed Pin
Nick Parker29-Jul-04 6:33
protectorNick Parker29-Jul-04 6:33 
GeneralDns.GetHostByAddress problem Pin
Dave@keyspell29-Jul-04 5:12
sussDave@keyspell29-Jul-04 5:12 
GeneralRe: Dns.GetHostByAddress problem Pin
Heath Stewart29-Jul-04 5:41
protectorHeath Stewart29-Jul-04 5:41 
GeneralRe: Dns.GetHostByAddress problem Pin
Dave@keyspell29-Jul-04 6:31
sussDave@keyspell29-Jul-04 6:31 
QuestionHow to Export to CSV file from DataSet? Pin
HyVong29-Jul-04 4:11
memberHyVong29-Jul-04 4:11 
AnswerRe: How to Export to CSV file from DataSet? Pin
Not Active29-Jul-04 5:13
mentorNot Active29-Jul-04 5:13 
AnswerRe: How to Export to CSV file from DataSet? Pin
Michael P Butler29-Jul-04 5:35
memberMichael P Butler29-Jul-04 5:35 
QuestionHow hard will it be to move to C# 2.0 ? Pin
Andres Coder29-Jul-04 4:02
memberAndres Coder29-Jul-04 4:02 
AnswerRe: How hard will it be to move to C# 2.0 ? Pin
SOCM_FP_CPP29-Jul-04 4:11
memberSOCM_FP_CPP29-Jul-04 4:11 
GeneralRe: How hard will it be to move to C# 2.0 ? Pin
Nick Parker29-Jul-04 6:07
protectorNick Parker29-Jul-04 6:07 
GeneralRe: How hard will it be to move to C# 2.0 ? Pin
SOCM_FP_CPP29-Jul-04 20:42
memberSOCM_FP_CPP29-Jul-04 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.181119.1 | Last Updated 20 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid