简体   繁体   English

如何仅从列表框输出一部分值?

[英]How to output only a part of values from ListBox?

I would like to output only a part of items from listBox1 like: response.response.items[counter].first_name to lable_name.Text . 我只想从listBox1输出项目的一部分,例如: response.response.items[counter].first_namelable_name.Text How can I do that? 我怎样才能做到这一点?

Part of method: 方法的一部分:

for (int counter = 0; counter < response.response.items.Count; counter++)
{
    listBox1.Items.Add(response.response.items[counter].first_name + " " + response.response.items[counter].last_name  + Environment.NewLine);
}

The way I output items to lable: 我将项目输出到标签的方式:

private void listBox1_DoubleClick(object sender, EventArgs e)
{
    int count = listBox1.Items.Count -1;

    for (int counter = count; counter >= 0; counter--)
    {
        if (listBox1.GetSelected(counter))
        { 
            lable_name.Text= listBox1.Items[counter].ToString();
        }
    }
}
lable_name.Text = listbox1.Items[counter].ToString().Split(' ')[0];

could be one of the options ... 可能是选项之一...

just make sure what charackter are qou spliting on as well as the text in string. 只要确保您正在拆分的字符以及字符串中的文本即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM