本文介绍了如何在单击事件按钮上将线串插入到列表视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
谁能帮助我如何在单击事件按钮上将线串插入到列表视图中.
基本上我的项目是基于餐厅的,如果我想在列表视图中添加 starter 和 main 课程,我想在它们之间用行字符串将它们分开像这样的两个不同的课程:
Hello
Could anyone help me how to insert a line string into listview on click event button.
Basically my project is restaurant based, for instant if I want to add a starter and a main course into my listview, I want to divide them with a line string in between the two different courses like so:
1 Soup £0.00
1 Bruschetta £0.00
****** Course 1 ******
1 Ravioli £0.00
1 Lasagne £0.00
1 Veg. Pizza £0.00
这是单击事件按钮的代码(请参见下文),但不显示任何内容.
This is the code of the click event button (see below) but its not displaying nothing.
private void cmdCourseSeparator_Click(object sender, EventArgs e)
{
string line1 = "════";
string line2 = "══════ Course 1 ══════";
string line3 = "══════";
string line4 = "══════ Course 2 ══════";
ListViewGroup liViGroup = new ListViewGroup();
liViGroup.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center;
if (liViGroup.Header == "Starter")
{
liViGroup.Items.Add(line1);
//foodItem.SubItems.Add(line2);
//foodItem.SubItems.Add(line3);
//foodItem.SubItems.Add(line3);
}
this.TableOrderListView.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {
liViGroup});
}
有人可以帮助我,告诉我我想念的是什么...
亲切的问候
Roni
Could someone please help me and tell what am I missing...
Kind Regards
Roni
推荐答案
ListViewGroup liViGroup = new ListViewGroup();
liViGroup.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center;
if (liViGroup.Header == "Starter") // No header was assigned to liViGroup, so it never enters this block
{
liViGroup.Items.Add(line1);
这篇关于如何在单击事件按钮上将线串插入到列表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!