Click here to Skip to main content
15,918,889 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataGridViewImageColumn Pin
e_LA31-Jul-06 21:31
e_LA31-Jul-06 21:31 
GeneralRe: DataGridViewImageColumn Pin
e_LA31-Jul-06 23:24
e_LA31-Jul-06 23:24 
GeneralIt works Pin
e_LA1-Aug-06 1:26
e_LA1-Aug-06 1:26 
QuestionCombining results of queries problem Pin
coolestCoder28-Jul-06 4:46
coolestCoder28-Jul-06 4:46 
AnswerIs there an index on field 2? Pin
Ennis Ray Lynch, Jr.28-Jul-06 4:58
Ennis Ray Lynch, Jr.28-Jul-06 4:58 
GeneralRe: Is there an index on field 2? Pin
coolestCoder28-Jul-06 5:24
coolestCoder28-Jul-06 5:24 
GeneralRe: Is there an index on field 2? Pin
Ennis Ray Lynch, Jr.28-Jul-06 6:37
Ennis Ray Lynch, Jr.28-Jul-06 6:37 
QuestionLIstViewItem.Remove() after label edit throws exception Pin
alekyork28-Jul-06 4:31
alekyork28-Jul-06 4:31 
An interesting problem:
I have a ListView with LabelEdit set to TRUE. When I change the label, I want to make some decisions as to whether the ListViewItem (that's just been edited) should stay in the ListView or not.
The natural place to inspect this is in the AfterLabelEdit event...
If the decision is to take the item out, I used the ListViewItem.Remove().
However - check this out:
A) say that the item's index is N (indices are zero-based)
B) if there exists an item after it (i.e. with index N+1)
then this item gets quietly removed
C) if the item is the last in the list,an exception is thrown
saying that index N (requested to be removed) is non-existant.

It looks like:
D) when the item is being edited, it is taken OUT of the
ListView.Items collection. So - the original item N+1 moves up and
is temporarily assigned index N (that is how it gets removed - see
B) above)
E) if however, item N is the last in the collection and gets
temporarily taken out while being edited, then of course we get
and exception thrown as there isn't an item with index N

This can easily be proved:
1. create a new Windows Forms project
2. add a ListView to the form
3. Set LabelEdit to TRUE
4. Add 3 items to the list, with labels e.g. 'Item1', 'Item2' and 'Item3'
5. Create a handler for the AfterLabelEdit event
6. Inside this handler add this code:

ListViewItem item = listView1.Items[e.Item];
item.Remove();


7. Run the application
8. Edit the first item and press Enter -> the second item is removed
9. Next, edit the last item then press Enter -> exception is thrown

This is all very nice... Frown | :-(

But - can someone suggest an elegant workaround , i.e. - where and
how can I remove items after they have been edited?

Many thanks in advance.





alekyork
AnswerRe: LIstViewItem.Remove() after label edit throws exception Pin
Rob Graham28-Jul-06 5:25
Rob Graham28-Jul-06 5:25 
QuestionProblems with state management of the DataGridViewCheckBox. HELP! Pin
LongRange.Shooter28-Jul-06 4:25
LongRange.Shooter28-Jul-06 4:25 
AnswerRe: Problems with state management of the DataGridViewCheckBox. HELP! Pin
Judah Gabriel Himango28-Jul-06 6:05
sponsorJudah Gabriel Himango28-Jul-06 6:05 
GeneralRe: Problems with state management of the DataGridViewCheckBox. HELP! Pin
LongRange.Shooter28-Jul-06 8:41
LongRange.Shooter28-Jul-06 8:41 
QuestionText in a Web Application Pin
orentuil28-Jul-06 3:22
orentuil28-Jul-06 3:22 
AnswerRe: Text in a Web Application Pin
peshawarcoder28-Jul-06 4:19
peshawarcoder28-Jul-06 4:19 
GeneralRe: Text in a Web Application Pin
peshawarcoder28-Jul-06 4:22
peshawarcoder28-Jul-06 4:22 
AnswerRe: Text in a Web Application Pin
peshawarcoder28-Jul-06 4:24
peshawarcoder28-Jul-06 4:24 
AnswerRe: Text in a Web Application Pin
peshawarcoder28-Jul-06 4:29
peshawarcoder28-Jul-06 4:29 
AnswerRe: Text in a Web Application [modified] Pin
BoneSoft28-Jul-06 4:40
BoneSoft28-Jul-06 4:40 
GeneralRe: Text in a Web Application Pin
orentuil29-Jul-06 8:47
orentuil29-Jul-06 8:47 
Question[Message Deleted] Pin
Rahul.RK28-Jul-06 3:08
Rahul.RK28-Jul-06 3:08 
AnswerRe: System Tray Icon Pin
Stefan Troschuetz28-Jul-06 3:16
Stefan Troschuetz28-Jul-06 3:16 
AnswerRe: System Tray Icon Pin
Cadence2.028-Jul-06 9:05
Cadence2.028-Jul-06 9:05 
QuestionBitfield access to array Pin
LiamD28-Jul-06 2:52
LiamD28-Jul-06 2:52 
AnswerRe: Bitfield access to array [modified] Pin
Dustin Metzgar28-Jul-06 3:29
Dustin Metzgar28-Jul-06 3:29 
Questionstruct Pin
honeyman_can28-Jul-06 2:44
honeyman_can28-Jul-06 2:44 

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.