【问题标题】:display single column in list view with two groups在包含两个组的列表视图中显示单列
【发布时间】:2011-11-02 16:16:19
【问题描述】:

我有客户表有列

                                      customer id
                                     customer name 

我有另一个名为地址的表 地址id 地址文本

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

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

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

像这样在列表视图中只有上图的单列

有没有人帮忙解决这个问题..

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

【问题讨论】:

  • 有没有人能帮忙解决这个问题...

标签: c# .net winforms listview grouping


【解决方案1】:

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

    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 });

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 是否可以只显示两个不同表中的地址名称和客户名称......只需在列表视图中显示两个组中的项目......
      猜你喜欢
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多