Click here to Skip to main content
15,891,708 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataGridView in C# Pin
peshawarcoder31-Aug-06 19:06
peshawarcoder31-Aug-06 19:06 
QuestionRegex.Replace Chr(10) Pin
J Liang31-Aug-06 4:01
J Liang31-Aug-06 4:01 
AnswerRe: Regex.Replace Chr(10) [modified] Pin
John Petersen31-Aug-06 5:14
John Petersen31-Aug-06 5:14 
GeneralRe: Regex.Replace Chr(10) Pin
J Liang31-Aug-06 5:50
J Liang31-Aug-06 5:50 
GeneralRe: Regex.Replace Chr(10) Pin
Guffa31-Aug-06 8:00
Guffa31-Aug-06 8:00 
GeneralRe: Regex.Replace Chr(10) Pin
John Petersen31-Aug-06 22:43
John Petersen31-Aug-06 22:43 
GeneralRe: Regex.Replace Chr(10) Pin
J Liang2-Sep-06 3:12
J Liang2-Sep-06 3:12 
QuestionLocking within a single thread Pin
Dan Neely31-Aug-06 3:55
Dan Neely31-Aug-06 3:55 
I have two listviews in my app. The user may make multiple selections in one of them, but may not have selections in both at the same time. To enforce this requirement I'm responding to the SelectedIndexChanged event and having it clear the selections in the other LV. The problem is that the clear() method operates incrementally and immediately fires the event in the listview it's working on, which results in both listviews clearing each others selections. I tried using the lock statement, but the second event handler is able to gain the lock even though the first hasn't completed. Since all the examples I've seen are for controlling across threads I'm assuming the problem is that the second event handler is being ran in the same thread as the first.

What happens is the following:
State: LV1 - 2 items selected, LV2 0 items selected
Click on an item in LV2
State: LV1 - 2 items selected, LV2 1 items selected
LV2 handler called. LV1.Clear method called.
LV1.Clear cancels the 1st selection in LV1
State: LV1 - 1 items selected, LV2 1 items selected
LV1 handler called. It calls LV2.Clear called.
LV2.Clear cancels the selection in LV2
State: LV1 - 1 items selected, LV2 0 items selected
second LV2 handler called. Terminates because LV2 has no items selected.
LV1.Clear() called by the first LV2 handler regains control. Remaining LV1 selection is now cleared.
State: LV1 - 0 items selected, LV2 0 items selected

The result I want is: State: LV1 - 0 items selected, LV2 1 items selected


I could use a bool flag as a psuedo-lock to control the updates but am hoping there's a more graceful way to do it.

LV2 has a handler identical to this.
private void LV1SelectedIndexChanged(object sender, System.EventArgs e)<br />
{<br />
	lock(this)<br />
	{<br />
		//stops recursive calling when clearing a single selection<br />
		if (this.LV1.SelectedItems.Count >0)<br />
		{<br />
			this.LV2.SelectedItems.Clear();<br />
		}<br />
	}<br />
}

AnswerRe: Locking within a single thread Pin
Not Active31-Aug-06 5:06
mentorNot Active31-Aug-06 5:06 
AnswerRe: Locking within a single thread Pin
Nader Elshehabi31-Aug-06 5:14
Nader Elshehabi31-Aug-06 5:14 
GeneralRe: Locking within a single thread Pin
Dan Neely31-Aug-06 5:54
Dan Neely31-Aug-06 5:54 
AnswerRe: Locking within a single thread Pin
mav.northwind31-Aug-06 7:37
mav.northwind31-Aug-06 7:37 
QuestionUsing COM? Pin
Dominik Reichl31-Aug-06 3:20
Dominik Reichl31-Aug-06 3:20 
AnswerRe: Using COM? Pin
Bhupi Bhai1-Sep-06 2:55
Bhupi Bhai1-Sep-06 2:55 
Questionsetup file Pin
TAREQ F ABUZUHRI31-Aug-06 2:36
TAREQ F ABUZUHRI31-Aug-06 2:36 
AnswerRe: setup file Pin
Nader Elshehabi31-Aug-06 4:52
Nader Elshehabi31-Aug-06 4:52 
Questionhow to create a new .net solution at the run time or from other solution Pin
Brosis31-Aug-06 2:23
Brosis31-Aug-06 2:23 
AnswerRe: how to create a new .net solution at the run time or from other solution Pin
Nader Elshehabi31-Aug-06 4:56
Nader Elshehabi31-Aug-06 4:56 
GeneralRe: how to create a new .net solution at the run time or from other solution Pin
Brosis31-Aug-06 18:34
Brosis31-Aug-06 18:34 
AnswerRe: how to create a new .net solution at the run time or from other solution Pin
Nader Elshehabi1-Sep-06 5:16
Nader Elshehabi1-Sep-06 5:16 
Questionhow to use MD5 technics Pin
narendrakumarp31-Aug-06 2:23
narendrakumarp31-Aug-06 2:23 
AnswerRe: how to use MD5 technics Pin
SharpenedC31-Aug-06 2:27
SharpenedC31-Aug-06 2:27 
AnswerRe: how to use MD5 technics Pin
Rob Philpott31-Aug-06 5:01
Rob Philpott31-Aug-06 5:01 
QuestionMemory Leak? Pin
SharpenedC31-Aug-06 2:03
SharpenedC31-Aug-06 2:03 
AnswerRe: Memory Leak? Pin
Martin#31-Aug-06 2:09
Martin#31-Aug-06 2:09 

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.