Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
GeneralRe: Back Porting Application Pin
pippyn13-Sep-07 6:41
pippyn13-Sep-07 6:41 
GeneralRe: Back Porting Application Pin
Dave Kreskowiak13-Sep-07 9:33
mveDave Kreskowiak13-Sep-07 9:33 
QuestionClosing a form Pin
Justin Perez13-Sep-07 4:38
Justin Perez13-Sep-07 4:38 
AnswerRe: Closing a form Pin
Lutosław13-Sep-07 4:50
Lutosław13-Sep-07 4:50 
AnswerRe: Closing a form Pin
Michael Potter13-Sep-07 4:57
Michael Potter13-Sep-07 4:57 
Questionhide/disable MyComputer/drives Pin
H.R13-Sep-07 4:30
H.R13-Sep-07 4:30 
AnswerRe: hide/disable MyComputer/drives Pin
Frank Kerrigan13-Sep-07 6:20
Frank Kerrigan13-Sep-07 6:20 
QuestionChecking if any items in a listbox are selected Pin
Lucy13-Sep-07 3:33
Lucy13-Sep-07 3:33 
I have 2 forms. On Form1 I have two listboxes. I want to allow the user to edit items in either listboxes by the use of two edit buttons (associated with 1 listbox each). When an item in listbox1 is selected then no items in listbox2 are selected (and vic versa). So when the first edit button is clicked to edit the selected item in listbox2, form2 is shown with a textbox. In this textbox is the text of the selected item. This should work the same for the second edit button but the selected item in listbox2 should be shown in the textbox on form2. To do this I have created two public strings and two public bools in form1:

public string item1
{
get { return listBox1.SelectedItem.ToString(); }
}
public bool selectedItem1
{
get { return Convert.ToBoolean(listBox1.SelectedIndex) == true; }
}

public string item2
{
get { return listBox2.SelectedItem.ToString(); }
}
public bool selectedItem2
{
get { return Convert.ToBoolean(listBox2.SelectedIndex) == true; }
}

In form2's load event I have the following if statement to check if listbox1 has a selected item or if listbox2 has a selected item:

if (Form1.selectedItem1 == true)
{
textBox1.Text = Form1.item1;
}
else if (Form1.selectedItem2 == true)
{
textBox1.Text = Form1.item2;
}

I have used a break point to follow this if statement and it seems as though it is not checking which listbox has an item selected.

Can anyone help please? How can I check which listbox has a selected item. Or can I turn this code into a public bool variable?:

if (listBox1.SelectedIndex >= 0)

Lucy
AnswerRe: Checking if any items in a listbox are selected Pin
Luc Pattyn13-Sep-07 4:03
sitebuilderLuc Pattyn13-Sep-07 4:03 
GeneralRe: Checking if any items in a listbox are selected Pin
Lucy13-Sep-07 4:23
Lucy13-Sep-07 4:23 
GeneralRe: Checking if any items in a listbox are selected Pin
alisardar13-Sep-07 10:03
alisardar13-Sep-07 10:03 
AnswerRe: Checking if any items in a listbox are selected Pin
led mike13-Sep-07 4:28
led mike13-Sep-07 4:28 
GeneralRe: Checking if any items in a listbox are selected Pin
Lucy13-Sep-07 4:42
Lucy13-Sep-07 4:42 
GeneralRe: Checking if any items in a listbox are selected Pin
led mike13-Sep-07 7:38
led mike13-Sep-07 7:38 
QuestionMemory Usage Pin
student_rhr13-Sep-07 3:21
student_rhr13-Sep-07 3:21 
AnswerRe: Memory Usage Pin
Guffa13-Sep-07 3:28
Guffa13-Sep-07 3:28 
GeneralRe: Memory Usage Pin
student_rhr13-Sep-07 4:12
student_rhr13-Sep-07 4:12 
GeneralRe: Memory Usage Pin
Lutosław13-Sep-07 4:53
Lutosław13-Sep-07 4:53 
AnswerRe: Memory Usage Pin
Urs Enzler13-Sep-07 3:57
Urs Enzler13-Sep-07 3:57 
AnswerRe: Memory Usage Pin
Judah Gabriel Himango13-Sep-07 9:47
sponsorJudah Gabriel Himango13-Sep-07 9:47 
QuestionReversible Cipher Question Pin
paas13-Sep-07 3:20
paas13-Sep-07 3:20 
AnswerRe: Reversible Cipher Question Pin
Colin Angus Mackay13-Sep-07 3:28
Colin Angus Mackay13-Sep-07 3:28 
AnswerRe: Reversible Cipher Question Pin
Dan Neely13-Sep-07 3:58
Dan Neely13-Sep-07 3:58 
GeneralRe: Reversible Cipher Question Pin
paas13-Sep-07 4:24
paas13-Sep-07 4:24 
GeneralRe: Reversible Cipher Question Pin
Mark Churchill13-Sep-07 15:29
Mark Churchill13-Sep-07 15:29 

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.