开发者

Listview filling issue

开发者 https://www.devze.com 2022-12-08 03:18 出处:网络
I need to know what are the things going on here.Actually my aim is to add a column additionally and display the contents.I Added column but i want to know

I need to know what are the things going on here.Actually my aim is to add a column additionally and display the contents.I Added column but i want to know the codeflow required to finish to display items in that column

ManagedDeviceCollection list = new ManagedDeviceCollection();
try
{
    if(SpoServer == null)
       return;

    _listSelected.BeginUpdate();
    _listAvailable.BeginUpdate();

    #region populate the selected list

    // Collect selected items.
    object[] selected = new object[_listSelected.SelectedItems.Count];
    _listSelected.SelectedItems.CopyTo(selected, 0);

    // Clear listview.
    _listSelected.Items.Clear();

    // Add systems.
    ResourcePolicySystemsLVI item;
    foreach(ManagedDevice md in PolicySystemsList)
    {
       item = new ResourcePolicySystemsLVI(md);
       item.Update();
       foreach(object obj in selected)
       {
          item.Selected = (((ResourcePolicySystemsLVI)obj).Data == item.Data);
          break;
       }
       _listSelected.Items.Add(item);
    }

    // Sort list.
    _listSelected.Sort();

    // Ensure selected items are visible.
    if(_listSelected.SelectedItems.Count > 0)
    {
       _listSelected.SelectedItems[_listSelected.SelectedItems.Count 
 开发者_Go百科          - 1].EnsureVisible();
       _listSelected.SelectedItems[0].EnsureVisible();
    }

    #endregion

    #region populate the available list

    // Collect selected items.
    selected = new object[_listAvailable.SelectedItems.Count];
    _listAvailable.SelectedItems.CopyTo(selected, 0);

    // Clear listview.
    _listAvailable.Items.Clear();

    // Add systems.
    ResourcePolicyAvailSystemsLVI item2;
    foreach(ManagedDevice md in AvailableSystemsList)
    {
       item2 = new ResourcePolicyAvailSystemsLVI(md);
       item2.Update();
       foreach(object obj in selected)
       {
           item2.Selected = (((ResourcePolicyAvailSystemsLVI)obj).Data 
               == item2.Data);
           break;
       }
       _listAvailable.Items.Add(item2);
    }

    // Sort list.
    _listAvailable.Sort();

    // Ensure selected items are visible.
    if(_listAvailable.SelectedItems.Count > 0)
    {
       _listAvailable.SelectedItems[_listAvailable.SelectedItems.Count 
           - 1].EnsureVisible();
       _listAvailable.SelectedItems[0].EnsureVisible();
    }

    #endregion

    _listSelected.EndUpdate();
    _listAvailable.EndUpdate();


To display text in columns after the first, use the ListViewItem.SubItems collection. For example, you might modify your main loop as follows:

item2 = new ResourcePolicyAvailSystemsLVI(md);
// skipped some of your code
item2.SubItems.Add("My second piece of info");  // this is what puts data into the second column

I wasn't sure from your question whether you had already added the requisite column to the ListView: if not, you must do so using ListView.Columns.Add in order to display the subitem.

0

精彩评论

暂无评论...
验证码 换一张
取 消