2016-08-09 44 views
0

我正在使用C#Windows窗体和一个codefirst数据库(Visual Studio 2013 Ultimate)。如何在Winfoms DataRepeater的另一个列表中显示列表

是否可以在Windows窗体的另一个列表中显示列表? (重点在于显示数据)。

请参阅此项目为例:https://postimg.cc/image/inunj8pxh/

我通常显示与powerpacks'的DataRepeater列表。例如,当客户下订单时,我可以显示订单列表的orderId,customerEmail,customerName等。

但是,每个订单包括许多不同的项目。到目前为止,我无法在每个显示父列表(订单)的datarepeater元素内显示子列表(项目)的任何元素。每个项目的外键是orderId,并且订单的外键是项目列表(关系订单...项目是1..n)。

+1

的图像将有助于了解你在找什么。另外:你对标签的选择似乎有点令人困惑。Treeview包含嵌套列表。除此之外,你需要自己编写代码。这是一个编码[手风琴示例](http://stackoverflow.com/questions/29005397/accordion-in-windows-forms-datagridview/29006361?s=1|0.4533#29006361) – TaW

+0

我很快创建了一个新项目,因为我的真实项目包含敏感数据。请查看这张图片,了解我的项目和可视化目标的完整概览。 https://postimg.org/image/inunj8pxh/ –

+0

嗯,这种情况下,你应该去嵌套的flowlayoutpanels和usercontrols ..你可能仍然不希望使用激活/扩展机制,如在手风琴的例子,但它doesn'看起来像一排紧密的网格;所以DGV似乎并不需要..如果您需要它,请不要忘记在进行布局时提前考虑数据绑定。 – TaW

回答

0

我找到了解决方案!我花了一段时间才弄清楚如何获得对数据处理器项目的控制权。通过阅读其他许多论坛和教程,我逐渐完成了自己的工作。在截图中查找我的完整项目: http://i.stack.imgur.com/jFa7G.png

代码中的任何改进都非常值得欢迎。由于我对整个编程世界相当陌生,因此我的代码可能无法优化,词汇的使用有时可能不准确。

这里你可以找到我的Form1的代码:

 
namespace list_inside_list 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     private void Form1_Load(object sender, EventArgs e) 
     {

} protected override void OnLoad(EventArgs e) { //First we load the list of Orders to datarepeater1 Program.CompanyContext _context = new Program.CompanyContext(); List<list_inside_list.Program.Order> listOrders = _context.Order.ToList(); program_OrderBindingSource1.DataSource = listOrders; //I don´t know why, but we need to load the list of items as well, although we never use the listItems variable List<list_inside_list.Program.Item> listItems = _context.Item.ToList(); /* * 1. We will loop through all the datarepater1 items (which is fed with listOrders) * 2. We assign currItem as datarepeater1.CurrentItem in order to "select" the current item at index j, * although we will never user currItem * 3. We tell the program that of the current datarepeater item we want use the current Order object * 4. We go through each of the currentOrder.items and print the itemName * */ DataRepeaterItem currItem = new DataRepeaterItem(); for (int j = 0; j < this.dataRepeater1.ItemCount; j++) { this.dataRepeater1.CurrentItemIndex = j; currItem = dataRepeater1.CurrentItem; var currentOrder = (list_inside_list.Program.Order)program_OrderBindingSource1.Current; foreach (var item in currentOrder.items) { dataRepeater1.CurrentItem.Controls["richTextBox1"].Text = dataRepeater1.CurrentItem.Controls["richTextBox1"].Text + item.itemName + "\n"; } } } }

}

相关问题