I'm trying to manage some processes

So ive created a listview, the first column contains the name of the processes, the second should contain the id of the process, but I honestly cannot figure out how to get it working, making the "ListViewItem" control, but its not really working as i thought, any idea on how i could solve this :(?


You have to pass a value to the 1st subitem of the listView, like that:

string name = "SomeName";
int id = 2;
ListViewItem lvi = new ListViewItem();
lvi.Text = name;

If you want to insert in a specific row, you have to create a loop of the listView`s rows:

for(int i = 0; i < listView1.Items.Count; i++)
    //same code here as abouve

may i ask, how do i associate a contextmenustrip to the selected item in my listview? :D


Check this..

<ListView Name="MyListView" >
             <ContextMenu Name="MyContextMenu">
                 <MenuItem Name="MyMenuItem1" Header="Menu Item1" Click="MenuItem_Click"/>
                 <MenuItem Name="MyMenuItem2" Header="Menu Item2" Click="MenuItem_Click"/>
            <GridViewColumn Header="ID" Width="Auto" DisplayMemberBinding="{Binding ID}" />                                    
            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path = Name}" Width="Auto" />


Hope this helps..


Sravanthi Ch

This article has been dead for over six months. Start a new discussion instead.