I need to send an array to a separate array for each time I click on an item in a listbox

1

I tried this code and it does not work for me

private void lstIngreso_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            index = lstIngreso.SelectedIndex;
            valor[index] = Convert.ToDecimal(lstIngreso.SelectedItem);
            cantidad[index] = contador++;

            foreach  (int i in cantidad)
            {
                contador = contador++;  
            }

Accountant I have declared it globally like this:

int contador=0;

the listbox looks like this:

0.10
0.20
0.30
0.50
1
2

The idea is that when I click on 0.10 for example I have to send to an arrangement how many coins of 0.10 cents or how many of .20 I chose. Now tell me but not separate for each value.

Thanks

    
asked by Adriana Rodriguez 26.11.2018 в 22:49
source

1 answer

0

Let's look at the simple problem that your logic has.

You do not need any global counter.

To know where you clicked, it is enough to add one to that position.

Your global counter, would help you to know the total of coins.

Then let's fix your code to the following way:

private void lstIngreso_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    index = lstIngreso.SelectedIndex;
    valor[index] = Convert.ToDecimal(lstIngreso.SelectedItem);
    //aca le sumamos uno a esa posicion.
    cantidad[index] += 1;
    //Aca sumamos uno al contador global
    contador++;  
}
    
answered by 27.11.2018 в 01:09