Error when use listbox to display data in function
NickName:user3226824 Ask DateTime:2014-02-23T17:48:53

Error when use listbox to display data in function

I want to display data in listbox , but I can not use listBox1 in function , I declare it in program but can not use in function , how can I use listBox1 in function to display data

void threetask(ref Int32 x,ref Int32 y)
{
  //do something
  listBox1.Items.Add(x);//error
  listBox1.Items.Add(y);//error
}


private void button2_Click(object sender, EventArgs e)
{ 
   ListBox listBox1 = new ListBox();
   this.Controls.Add(listBox1);
   threetask(ref x,ref y);
}

Copyright Notice:Content Author:「user3226824」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/21966656/error-when-use-listbox-to-display-data-in-function

More about “Error when use listbox to display data in function” related questions

Error when use listbox to display data in function

I want to display data in listbox , but I can not use listBox1 in function , I declare it in program but can not use in function , how can I use listBox1 in function to display data void threeta...

Show Detail

Display the result of a method in a Listbox

I have created a WCF project where i am trying to display some information in a listbox. I want when i click on a button, it will call my method and display it in a listbox. My method works fine bu...

Show Detail

Display error about databinding listbox

allow me to describe the error first. 1. display order error listbox will display items while begin with the second one, and the first goes to the last but four. the last item also has the same p...

Show Detail

When listbox item is selected display related data in another listbox

I am building an app with WPF C# and trying to display values in a list box which shows when an item from another list box is selected. Both list boxes need to get data from my SQL database. listb...

Show Detail

Could convert data type in listbox databinding when display in WPF?

I use a float type data set as a data source to bind to ListBox, but the first field in the collection of data is DateTime data type conversion float type. Now after binding display or floating-point

Show Detail

How to display record from listbox to data table or gridview?

I have listbox1 and listbox2. When I click a button, the item from listbox1 transfers to listbox2. My problem is, I only want to display on the gridview, listbox2 and not all the item from listbo...

Show Detail

C# Which Event should I use to display data in a textbox when I select an item in a listbox?

C# Which Event should I use to display data in a textbox when I select an item in a listbox? I want to select an item in a list box (winforms) and then a textbox near by show some data related to ...

Show Detail

Window with ListBox is not displaying error on the ListBox

I have a dialog in my WPF application which contains a ListBox. The ListBox uses the following DataTemplate to display its contents: <DataTemplate x:Key="AlarmClassTemplate"> <CheckBox

Show Detail

Listbox Data Using Filter Function in Excel, but how to sort by Date/Value in the Listbox itself?

I have userform with Listbox and text box to search. I'm using listbox to show whatever you type in textbox search using Filter Function in Excel. So basically, I just make filter function in excel...

Show Detail

xpages: computed field display multiple values in listbox with onchange event

I would like to ask how to use the computed field to display listbox value? My idea is there is a listbox and a computed field. In the listbox, I use partial update in the onchange event and the p...

Show Detail