Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
QuestionInheritance and reflection Pin
Russell Jones29-Mar-07 23:15
Russell Jones29-Mar-07 23:15 
AnswerRe: Inheritance and reflection Pin
Stefan Troschuetz29-Mar-07 23:36
Stefan Troschuetz29-Mar-07 23:36 
GeneralRe: Inheritance and reflection Pin
Russell Jones30-Mar-07 0:00
Russell Jones30-Mar-07 0:00 
AnswerRe: Inheritance and reflection Pin
DavidNohejl29-Mar-07 23:59
DavidNohejl29-Mar-07 23:59 
GeneralRe: Inheritance and reflection Pin
Russell Jones30-Mar-07 0:40
Russell Jones30-Mar-07 0:40 
GeneralRe: Inheritance and reflection Pin
DavidNohejl30-Mar-07 0:54
DavidNohejl30-Mar-07 0:54 
GeneralRe: Inheritance and reflection Pin
Russell Jones30-Mar-07 2:14
Russell Jones30-Mar-07 2:14 
QuestionProblems when removing from ListBox Pin
sinosoidal29-Mar-07 22:56
sinosoidal29-Mar-07 22:56 
Hi,

I'm creating something looked like the development enviorment in Visual Studio.

I have a panel with a listbox for "Activities".

I also have a panel with properties to change those activities properties.

I'm working on the deletion of activities but i'm having problems with the listbox.

i have the following two functions

<br />
private void lbActivities_SelectedIndexChanged(object sender, EventArgs e)<br />
        {<br />
            if (lbActivities.Items.Count!=0)<br />
            {<br />
                selectedActivityName = lbActivities.SelectedItem.ToString();<br />
                selectedActivityIndex = activities.FindIndex(withName);<br />
<br />
                pgProperties.SelectedObject = activitiesPropertyBags[selectedActivityIndex];<br />
            }<br />
        }<br />


This is a event for the listbox item change.

Well, i use two global variables to keep track of the selected item name and index. I also use a list to store my activities.

(is this stupid? could i use the listbox to do the same as the list, and avoid the use of two different structures?)

And here i have the code for deletion:

<br />
if (lbActivities.Items.Count != 0)<br />
            {<br />
                if (selectedActivityIndex == 0) {<br />
                    selectedActivityIndex = (lbActivities.Items.Count - 1) - 1;<br />
                    lbActivities.SelectedItem = lbActivities.Items[selectedActivityIndex];<br />
                }<br />
                else {<br />
                    selectedActivityIndex = lbActivities.SelectedIndex - 1;<br />
                    lbActivities.SelectedItem = lbActivities.Items[selectedActivityIndex];<br />
                }<br />
<br />
                lbActivities.Items.Remove(selectedActivityName);<br />
                activities.RemoveAt(activities.FindIndex(withName));<br />
            }<br />
        }<br />


The problem is that when the lbActivities.Items.Remove(selectedActivityName); is executed, the SelectedIndexChanged callback is called, and occurs an exception in the following instruction:

selectedActivityName = lbActivities.SelectedItem.ToString();

This happens even after i wrote the code above, which trys to change the selected item in order to avoid the selection of non existent item.

Any tips?

Thank you very much,

Nuno
AnswerRe: Problems when removing from ListBox Pin
Russell Jones29-Mar-07 23:30
Russell Jones29-Mar-07 23:30 
AnswerRe: Problems when removing from ListBox Pin
sinosoidal30-Mar-07 0:40
sinosoidal30-Mar-07 0:40 
QuestionCreating a custom Vista HotFix INstaller..plz help Pin
ke3p_up29-Mar-07 22:34
ke3p_up29-Mar-07 22:34 
AnswerRe: Creating a custom Vista HotFix INstaller..plz help Pin
stancrm30-Mar-07 0:55
stancrm30-Mar-07 0:55 
GeneralRe: Creating a custom Vista HotFix INstaller..plz help Pin
ke3p_up30-Mar-07 2:00
ke3p_up30-Mar-07 2:00 
GeneralRe: Creating a custom Vista HotFix INstaller..plz help Pin
ke3p_up30-Mar-07 2:45
ke3p_up30-Mar-07 2:45 
QuestionHow to Call AddIn function from App Pin
swje29-Mar-07 22:23
swje29-Mar-07 22:23 
QuestionLoad xml string with ‘&’ sign Pin
anderslundsgard29-Mar-07 21:59
anderslundsgard29-Mar-07 21:59 
AnswerRe: Load xml string with ‘&’ sign Pin
Guffa29-Mar-07 22:01
Guffa29-Mar-07 22:01 
GeneralRe: Load xml string with ‘&’ sign Pin
anderslundsgard30-Mar-07 1:31
anderslundsgard30-Mar-07 1:31 
Questionan error! unable to find manfiest? Pin
barak16048729-Mar-07 21:49
barak16048729-Mar-07 21:49 
AnswerRe: an error! unable to find manfiest? Pin
gauthee29-Mar-07 23:31
gauthee29-Mar-07 23:31 
QuestionCopy data into datagridview Pin
JacquesDP29-Mar-07 20:35
JacquesDP29-Mar-07 20:35 
AnswerRe: Copy data into datagridview Pin
gauthee29-Mar-07 23:53
gauthee29-Mar-07 23:53 
GeneralRe: Copy data into datagridview Pin
JacquesDP30-Mar-07 0:09
JacquesDP30-Mar-07 0:09 
Questiondatagrid very urgent Pin
vijayashanthi29-Mar-07 20:25
vijayashanthi29-Mar-07 20:25 
AnswerRe: datagrid very urgent Pin
gauthee30-Mar-07 0:00
gauthee30-Mar-07 0:00 

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.