views:

80

answers:

1

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 
           - 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();
A: 

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.

itowlson
i added new column,,but this listview already had two column, but i dont know how they r displayin datas to that column ,,a different way
peter
Not sure I understand the comment, Peter -- not sure who "they" are or what "a different way" refers to. To display data in the additional column(s), use ListViewItem.SubItems.Add. If I've misunderstood the comment then could you clarify what's not working for you or what additional info you need?
itowlson
Can you explain this bit of code from the begginning itself
peter
You create a new ListViewItem (which you are calling item2) and add it to the ListView.Items. This is what you're already doing and it causes the row to be displayed, with the ListViewItem content in the first column. Then you call item2.SubItems.Add(). This is the new bit and it causes the new subitem to appear in the next column (in this case the second column).
itowlson