C# 在tablelayuot中添加标签

发布于 2024-09-17 22:01:14 字数 1047 浏览 6 评论 0原文

我尝试向表格布局添加标签和行。当我像这样添加到列表视图时:

ListViewItem ite = new ListViewItem(tag);
ite.Text = (tag + " " + description + war);
listView2.Items.Add(ite.Text);

它有效,但是当我尝试另一个时它不起作用。为什么?没有任何错误或异常。

 foreach (DataElement elementy in sq)
 {                       
       for (int k = 0; k == row_number; k = k + 1)
        {
        tag = elementy.Tag.ToString();
        description = elementy.VR.Tag.GetDictionaryEntry().Description;



       // ListViewItem ite = new ListViewItem(tag);
        //ite.Text = (tag + " " + description + war);
        //listView2.Items.Add(ite.Text);

            tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            Label et_tag = new Label();
            et_tag.AutoSize= true;
            et_tag.Text = tag;
            tableLayoutPanel1.Controls.Add(et_tag, 0, k);
            Label op = new Label();
            op.AutoSize = true;
            op.Text = description;
            tableLayoutPanel1.Controls.Add(op, 1, k);

        }
 }

I tried to add labels and rows to tablelayout. When i used adding to listview like that:

ListViewItem ite = new ListViewItem(tag);
ite.Text = (tag + " " + description + war);
listView2.Items.Add(ite.Text);

it work,but when i try another it doesn't work. Why? There aren't any errors or exceptions.

 foreach (DataElement elementy in sq)
 {                       
       for (int k = 0; k == row_number; k = k + 1)
        {
        tag = elementy.Tag.ToString();
        description = elementy.VR.Tag.GetDictionaryEntry().Description;



       // ListViewItem ite = new ListViewItem(tag);
        //ite.Text = (tag + " " + description + war);
        //listView2.Items.Add(ite.Text);

            tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
            Label et_tag = new Label();
            et_tag.AutoSize= true;
            et_tag.Text = tag;
            tableLayoutPanel1.Controls.Add(et_tag, 0, k);
            Label op = new Label();
            op.AutoSize = true;
            op.Text = description;
            tableLayoutPanel1.Controls.Add(op, 1, k);

        }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヤ经典坏疍 2024-09-24 22:01:14

除非 row_number 为 0,否则内部 for 循环不会运行。否则,它将在 K 初始化后立即满足其条件,因此不执行任何操作。您的循环几乎肯定没有运行。如果 row_number 实际上 0,则循环将为外部 foreach 循环中的每个项目运行一次。

您希望循环在什么条件下运行?你的意思是k < row_number 来代替?您是否只想对其中 k == row_number 的单个 k 执行此操作,在这种情况下,您应该简单地将 row_number 分配给 k 并完全摆脱循环?我不知道row_number从哪里来,所以我不知道这段代码想要做什么。

Your inner for loop won't run unless row_number is 0. Otherwise, it will fail its condition immediately after K is initialized and, as a consequence, do nothing. Your loop almost certainly isn't running. If row_number actually is 0, your loop will run exactly once for every item in your outer foreach loop.

What condition do you want the loop to run on? Do you mean k < row_number instead? Do you just want to do this for a single k where k == row_number, in which case you should simply assign row_number to k and get rid of the loop entirely? I don't know where row_number comes from, so I don't know what this code wants to do.

半窗疏影 2024-09-24 22:01:14

不确定你如何初始化 row_number,但也许应该是这样的:

for (int k = 0; k <= row_number; k = k + 1)

Not sure how you're initializing row_number, but perhaps it should be something like:

for (int k = 0; k <= row_number; k = k + 1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文