Hey

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 :(?

Regards
-Jazerix

Recommended Answers

All 4 Replies

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;
lvi-Subitems.Add(id.ToString());
listView1.Items.Add(lvi);

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
}

Hell yeah ^^

thanks, worked perfectly ^^!

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

Hi,

Check this..

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

>


Hope this helps..


Regargds,

Sravanthi Ch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.