Click here to Skip to main content
15,904,497 members
Home / Discussions / C#
   

C#

 
GeneralDifferent behavior on different machines Pin
DougW4829-Jul-04 9:22
DougW4829-Jul-04 9:22 
GeneralRe: Different behavior on different machines Pin
Heath Stewart29-Jul-04 9:36
protectorHeath Stewart29-Jul-04 9:36 
GeneralRe: Different behavior on different machines Pin
DougW4829-Jul-04 9:59
DougW4829-Jul-04 9:59 
GeneralCryptography Pin
Wender Oliveira29-Jul-04 9:14
Wender Oliveira29-Jul-04 9:14 
GeneralRe: Cryptography Pin
Heath Stewart29-Jul-04 9:22
protectorHeath Stewart29-Jul-04 9:22 
Questioncontrol InvokeRequired() always necessary? Pin
vista2729-Jul-04 8:32
vista2729-Jul-04 8:32 
AnswerRe: control InvokeRequired() always necessary? Pin
Judah Gabriel Himango29-Jul-04 8:58
sponsorJudah Gabriel Himango29-Jul-04 8:58 
AnswerRe: control InvokeRequired() always necessary? Pin
Nick Parker29-Jul-04 9:07
protectorNick Parker29-Jul-04 9:07 
GeneralRe: control InvokeRequired() always necessary? Pin
Heath Stewart29-Jul-04 9:13
protectorHeath Stewart29-Jul-04 9:13 
GeneralRe: control InvokeRequired() always necessary? Pin
Nick Parker29-Jul-04 9:28
protectorNick Parker29-Jul-04 9:28 
GeneralRe: control InvokeRequired() always necessary? Pin
Heath Stewart29-Jul-04 9:39
protectorHeath Stewart29-Jul-04 9:39 
GeneralRe: control InvokeRequired() always necessary? Pin
Judah Gabriel Himango29-Jul-04 9:39
sponsorJudah Gabriel Himango29-Jul-04 9:39 
AnswerRe: control InvokeRequired() always necessary? Pin
Heath Stewart29-Jul-04 9:16
protectorHeath Stewart29-Jul-04 9:16 
GeneralInstantiating an array of objects Pin
crushinghellhammer29-Jul-04 8:11
crushinghellhammer29-Jul-04 8:11 
GeneralRe: Instantiating an array of objects Pin
Nick Parker29-Jul-04 9:11
protectorNick Parker29-Jul-04 9:11 
GeneralRe: Instantiating an array of objects Pin
crushinghellhammer29-Jul-04 9:32
crushinghellhammer29-Jul-04 9:32 
GeneralRe: Instantiating an array of objects Pin
Nick Parker29-Jul-04 10:11
protectorNick Parker29-Jul-04 10:11 
GeneralWM_PRINT for themed controls Pin
Mathew Hall29-Jul-04 6:31
Mathew Hall29-Jul-04 6:31 
GeneralRe: WM_PRINT for themed controls Pin
Heath Stewart29-Jul-04 9:25
protectorHeath Stewart29-Jul-04 9:25 
GeneralCalculating Point locations in relation to Parent client area. Pin
Tristan Rhodes29-Jul-04 6:27
Tristan Rhodes29-Jul-04 6:27 
GeneralRe: Calculating Point locations in relation to Parent client area. Pin
Nick Parker29-Jul-04 8:06
protectorNick Parker29-Jul-04 8:06 
GeneralRe: Calculating Point locations in relation to Parent client area. Pin
Anonymous30-Jul-04 13:42
Anonymous30-Jul-04 13:42 
GeneralCheckedListBox event handling strangeness Pin
James Kolpack29-Jul-04 5:32
James Kolpack29-Jul-04 5: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 8:01
protectorNick Parker29-Jul-04 8:01 
GeneralRe: CheckedListBox event handling strangeness Pin
James Kolpack29-Jul-04 8:31
James Kolpack29-Jul-04 8:31 

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.