开发者

List view new line for new values

The following code produces a ListView with the names of the custom开发者_JS百科ers:

private void displayDeliveries()
{
    lstDeliveryDetails.Items.Clear();
    foreach (Delivery d in mainForm.myDeliveries)
    {
        lstDeliveryDetails.Items.Add(d.DeliveryName);

    }
}

If I add, (d.DeliveryAddress), how can I get it to line up alongside the correct name?


I assume you mean that you want the delivery address to appear in the next column.

  1. Set ListView's View property to Details.
  2. Add two columns to the ListView's Collumns collection
  3. Use the following code to populate the ListView
private void displayDeliveries() 
{ 
    lstDeliveryDetails.Items.Clear(); 
    foreach (Delivery d in mainForm.myDeliveries) 
    { 
        ListViewItem item = lstDeliveryDetails.Items.Add(d.DeliveryName); 
        item.SubItems.Add(d.DeliveryAddress);  
    } 
}


Assuming want to have the Address followed by the name in each list item:

foreach (Delivery d in mainForm.myDeliveries)
{
    lstDeliveryDetails.Items.Add(d.DeliveryName + " " + d.DeliveryAddress);
}

This simply concatenates the DeliveryName with a space (" ") and then the DeliveryAddress strings.


Change the code in the for loop to:

ListViewItem item = lstDeliveryDetails.Items.Add(d.DeliveryName);  
item.SubItems.Add(d.DeliveryAddress);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜