Listview problems 
Author Message
 Listview problems

Please help me!!
I have a ListView in list mode
i add items like :
<code>
for (int i=0;i<10;i++){
        listView1.Items.Add("xxx");
Quote:
};

</code>
I use an event handler for selected index changhed like
<code>
private void listView1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
        string text=listView1.SelectedItems[0].Text;
         MessageBox.Show(text);

Quote:
}

</code >
on the first click all ok
on the second click on list to select an other element i get
i'm using Visual C# standard edition so .... can u help me

********************************************************************************
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentOutOfRangeException: Specified argument was out of the
range of valid values.
Parameter name: index
    at
System.Windows.Forms.SelectedListViewItemCollection.get_Item(Int32 index)
    at WebConfTool.Form1.listView1_SelectedIndexChanged(Object sender,
EventArgs e) in c:\teo\testc#\webconftool\webconftool\form1.cs:line 336
    at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)
    at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
    at System.Windows.Forms.ListView.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
     Assembly Version: 1.0.3300.0
     Win32 Version: 1.0.3705.0
     CodeBase:
file:///c:/winnt/microsoft.net/framework/v1.0.3705/mscorlib.dll
----------------------------------------
WebConfTool
     Assembly Version: 1.0.943.20818
     Win32 Version: 1.0.943.20818
     CodeBase:
file:///C:/teo/testc%23/WebConfTool/WebConfTool/bin/Debug/WebConfTool.exe
----------------------------------------
System.Windows.Forms
     Assembly Version: 1.0.3300.0
     Win32 Version: 1.0.3705.0
     CodeBase:
file:///c:/winnt/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
     Assembly Version: 1.0.3300.0
     Win32 Version: 1.0.3705.0
     CodeBase:
file:///c:/winnt/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
     Assembly Version: 1.0.3300.0
     Win32 Version: 1.0.3705.0
     CodeBase:
file:///c:/winnt/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Xml
     Assembly Version: 1.0.3300.0
     Win32 Version: 1.0.3705.0
     CodeBase:
file:///c:/winnt/assembly/gac/system.xml/1.0.3300.0__b77a5c561934e089/system.xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
     <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT de{*filter*} registered on the machine
rather than being handled by this dialog.

**************************************************************************************************************************



Mon, 17 Jan 2005 17:47:54 GMT  
 Listview problems
That happens because the IndexChanged event handler *also* gets called when
the
item is deselected. Remember that when you switch your selection from Item-A
to Item-B first Item-A gets a changed event because it is no longer
selected. At
that moment the count of selected indexes will be *zero* and therefore you
get
the out of bounds exception.

Simply add code in your event handler so that it acts appropriately (or
simply
returns without action) when the listView.Items.Count is zero.

Regards,
D. Emilio Grimaldo


Quote:
> Please help me!!
> I have a ListView in list mode
> i add items like :
> <code>
> for (int i=0;i<10;i++){
> listView1.Items.Add("xxx");
> };
> </code>
> I use an event handler for selected index changhed like
> <code>
> private void listView1_SelectedIndexChanged(object sender,
> System.EventArgs e)
> {
> string text=listView1.SelectedItems[0].Text;
> MessageBox.Show(text);

> }
> </code >
> on the first click all ok
> on the second click on list to select an other element i get
> i'm using Visual C# standard edition so .... can u help me

****************************************************************************
****

- Show quoted text -

Quote:
> See the end of this message for details on invoking
> just-in-time (JIT) debugging instead of this dialog box.

> ************** Exception Text **************
> System.ArgumentOutOfRangeException: Specified argument was out of the
> range of valid values.
> Parameter name: index
>     at
> System.Windows.Forms.SelectedListViewItemCollection.get_Item(Int32 index)
>     at WebConfTool.Form1.listView1_SelectedIndexChanged(Object sender,
> EventArgs e) in c:\teo\testc#\webconftool\webconftool\form1.cs:line 336
>     at System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)
>     at System.Windows.Forms.ListView.WmReflectNotify(Message& m)
>     at System.Windows.Forms.ListView.WndProc(Message& m)
>     at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
>     at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
>     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
> msg, IntPtr wparam, IntPtr lparam)

> ************** Loaded Assemblies **************
> mscorlib
>      Assembly Version: 1.0.3300.0
>      Win32 Version: 1.0.3705.0
>      CodeBase:
> file:///c:/winnt/microsoft.net/framework/v1.0.3705/mscorlib.dll
> ----------------------------------------
> WebConfTool
>      Assembly Version: 1.0.943.20818
>      Win32 Version: 1.0.943.20818
>      CodeBase:
> file:///C:/teo/testc%23/WebConfTool/WebConfTool/bin/Debug/WebConfTool.exe
> ----------------------------------------
> System.Windows.Forms
>      Assembly Version: 1.0.3300.0
>      Win32 Version: 1.0.3705.0
>      CodeBase:

file:///c:/winnt/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e
089/system.windows.forms.dll
Quote:
> ----------------------------------------
> System
>      Assembly Version: 1.0.3300.0
>      Win32 Version: 1.0.3705.0
>      CodeBase:

file:///c:/winnt/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
Quote:
> ----------------------------------------
> System.Drawing
>      Assembly Version: 1.0.3300.0
>      Win32 Version: 1.0.3705.0
>      CodeBase:

file:///c:/winnt/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/sy
stem.drawing.dll
Quote:
> ----------------------------------------
> System.Xml
>      Assembly Version: 1.0.3300.0
>      Win32 Version: 1.0.3705.0
>      CodeBase:

file:///c:/winnt/assembly/gac/system.xml/1.0.3300.0__b77a5c561934e089/system
.xml.dll

- Show quoted text -

Quote:
> ----------------------------------------

> ************** JIT Debugging **************
> To enable just in time (JIT) debugging, the config file for this
> application or machine (machine.config) must have the
> jitDebugging value set in the system.windows.forms section.
> The application must also be compiled with debugging
> enabled.

> For example:

> <configuration>
>      <system.windows.forms jitDebugging="true" />
> </configuration>

> When JIT debugging is enabled, any unhandled exception
> will be sent to the JIT de{*filter*} registered on the machine
> rather than being handled by this dialog.

****************************************************************************
**********************************************

- Show quoted text -



Mon, 17 Jan 2005 17:59:40 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Windows Form ListView problem

2. ListView-Problem in conjunction with COM

3. REALLY annoying listview problem

4. REALLY annoying listview problem

5. Listview problem

6. ListView Problem!!(Right button popup menu)

7. ListView Problem.

8. ListView problems: Displaying a button in a column

9. Listview problems : Handling LVN_ITEMCHANGING

10. Listview problems:how do i display a button on the listcontrol

11. CustomDraw in ListView problem

12. CustomDraw service in ListViews Problem

 

 
Powered by phpBB® Forum Software