0
votes

I want to delete some parts (string or int values) for selected listbox item in C#.

As shown on picture I get some random coordinates on picturebox which is shown on Listbox1. Then I selected randomly these points to add Listbox2 by ADD button. 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 ..)

Secondly I want to transfer to coordinate (just numbers) to Listbox3. How can I do?

Image
(source: 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);

                }
            }
        }
1
Your question is still unclear however.. you say you randomly select points but then you don't want them to be randomly selected?Sayse
I suppose you are working on WPF project. You should have 3 ObservableCollection properties in your view model which are bound to your list boxes. On button clicks you can manipulate those collections as you want.Vladimir Sachek
Yes, I am working C# windows from application. Whenever I clicked picturebox. Picturebox coordinates transfer to listbox. Then I want to delete some part on listbox1 and transfer to Listbox2ceng
C# windows from and WPF are very different kind of applications. Could you clarify which type of project you are working on?Vladimir Sachek
I am really sorry. Just a second I understand wrongly. I am using microsoft visual studio windows form application again sorryceng

1 Answers

0
votes

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.

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);
.