Search code examples
c#items

Non-invocable member 'ListBox.Items" cannot be used like a method


So this code should e correct since it was converted from VB to C# and it gives me this error.

         private void lstItems_DoubleClick(object sender, EventArgs e)
        {
        // validate item is selected
        int itemIndex = lstItems.SelectedIndex;

        // get price of selected item and add to order list
        lstOrder.Items.Add(lstItems.Items(itemIndex).ToString());
        decimal ThisPrice = listItemPrices[itemIndex];
        listOrderPrices.Add(ThisPrice);
        recalculateTotals();

        // get string value of selected item and add to order listbox


        // display totals from calculation performing functions
       }

My error is on the lstOrder.Items.Add(lstItems.Items(itemIndex).ToString((); How do I get rid of this error?


Solution

  • Visual Basic is fairly unique in using parentheses for array indexing. When you converted to C#, you forgot to switch this to the standard square brackets. lstItems.Items(itemIndex) should be lstItems.Items[itemIndex].