简体   繁体   English

删除所选列表框项目的某些部分

[英]Delete some part of selected listbox item

I want to delete some parts (string or int values) for selected listbox item in C#. 我想删除C#中所选列表框项的某些部分(字符串或整数值)。

As shown on picture I get some random coordinates on picturebox which is shown on Listbox1. 如图所示,我在Picturebox1上获得了一些随机坐标。 Then I selected randomly these points to add Listbox2 by ADD button. 然后,我随机选择这些点以通过“添加”按钮添加Listbox2。 I want make new arrangement at Listbox2 which means it should be 1.selected point 2.3.4.selected points ..(not randomly 3.rd 6.th 7.th ..) 我想在Listbox2上进行新的安排,这意味着它应该是1.selected point 2.3.4.selected points ..(不是随机的3.rd 6.th 7.th ..)

Secondly I want to transfer to coordinate (just numbers) to Listbox3. 其次,我想将坐标(仅数字)转移到Listbox3。 How can I do? 我能怎么做?

图片
(source: hizliresim.com ) (来源: hizliresim.com

To add selected coordinate 添加所选坐标

 private void add()
        {
            int c = listBox1.Items.Count - 1;

            for (int i = c; i >= 0; i--)
            {
                if (listBox1.GetSelected(i))
                {
                    int a = listBox2.Items.Count + 1;
                    listBox2.Items.Add(a+" "+listBox1.Items[i]);
                 //   listBox1.Items.RemoveAt(i);

                }
            }
        }

The question is not really clear but i will try to give you an answer as good as i understood the question. 这个问题还不是很清楚,但是我会尽我所能回答给你一个答案。 So from what i got you would like to make it so the numbers are "1 ,2 ,3 ..." in ListBox2 instead of random once and also you would like the same result but only the numbers in ListBox3. 所以从我得到的结果来看,您想使它成为ListBox2中的数字“ 1、2、3 ...”,而不是随机的一次,并且您也希望得到相同的结果,但仅是ListBox3中的数字。

Hope this help at least this is what i understood you are trying to do. 希望这至少可以帮到我,我了解您正在尝试这样做。 Btw all this is assuming that all your data is based on the example you provided! 顺便说一句,所有这些都假设您的所有数据都基于您提供的示例!

//We are going to read the string from the first box and find the first 
//occurence of "." and get the rest of the string after that we are going to add it to ListBox2
        string for_lisbox2 = listBox1.Items[i].ToString();
        for_lisbox2 = for_lisbox2.Substring(for_lisbox2.IndexOf('.'));
        int current_index = listBox2.Items.Count + 1;
        listBox2.Items.Add(current_index + for_lisbox2);

//Then we do something similar but this time we are finding last empty space " " so we can find the start of the second coordinates and we mark it as Y
//then we do the same with X and finaly we add them to Lisbox3

        string for_listbox3 = for_lisbox2;

        //finding second set of coordinates by finding the last occurence of ' ' and using the result for a start index of Substring method this will return the second number
        string Y = for_listbox3.Substring(for_listbox3.LastIndexOf(' '));

        // this is just to remove the numbers that we just got in the previous line so they are not in your way for the next operation
        for_listbox3 = for_listbox3.Substring(0, for_listbox3.LastIndexOf(' '));

        //this is just like geting the other number
        string X = for_listbox3.Substring(for_listbox3.LastIndexOf(' '));

        for_listbox3 = X + " " + Y;//displaying the results in ListBox3 as "72 134"

        listBox3.Items.Add(for_listbox3);
.

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

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