在列表视图中显示具有两个组的单个列

时间:2011-08-24 10:13:00

标签: c# .net winforms listview grouping

我的客户表中有

                                      customer id
                                     customer name 

我有另一个名为address的表                                         addressid                                         addresstext

现在我想显示像这样的客户名称和地址文本

                    customers
                    -----------
                    customer name 1
                    customer name 2
                    customer name 3

                    addresses 
                    -----------
                    addresstext 1
                    addresstext 2
                    addresstext 3

这样在列表视图中只有图enter image description here

上方的单个列

任何人都可以帮忙...

我在winforms应用程序中使用c#

3 个答案:

答案 0 :(得分:5)

非常感谢您的支持,我已经解决了我的问题........像这样

    lstviewcategories.View = View.Details; 
    lstviewcategories.Columns.Add(new ColumnHeader() { Width = lstviewcategories.Width - 20 }); 
    lstviewcategories.HeaderStyle = ColumnHeaderStyle.None; 
    lstviewcategories.Sorting = SortOrder.Ascending; 
    lstviewcategories.Dock = DockStyle.None; 

    ListViewGroup categorygroup = new ListViewGroup("Category Types",HorizontalAlignment.Center); 
    lstviewcategories.Groups.Add(categorygroup); 


    var categorytypes = (from categories in abc.categories 
                         select categories.category_Name).ToList(); 

    lstviewcategories.Items.Add(new ListViewItem() { Text = "ALL", Group = categorygroup }); 
    foreach (string item in categorytypes) 
    { 

        lstviewcategories.Items.Add(new ListViewItem() { Text = item.ToString(), Group = categorygroup }); 

    } 

    ListViewGroup pricerangegroup = new ListViewGroup("Price Ranges", HorizontalAlignment.Center); 
    lstviewcategories.Groups.Add(pricerangegroup); 

    lstviewcategories.Items.Add(new ListViewItem() { Text = "ALL", Group = pricerangegroup }); 
    lstviewcategories.Items.Add(new ListViewItem() { Text = "0-500", Group = pricerangegroup }); 
    lstviewcategories.Items.Add(new ListViewItem() { Text = "500-1000", Group = pricerangegroup }); 
    lstviewcategories.Items.Add(new ListViewItem() { Text = "1000+", Group = pricerangegroup });

答案 1 :(得分:0)

您需要在地址表上创建一个指向客户ID的外键。

答案 2 :(得分:0)

如果您询问如何使用sql表中的数据填充列表视图,那么请查看

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2725cfac-76a0-42f3-90b2-93c6ab96d901/