How to load Items in combo box on Formload from a class file
I would like to load the items that were declared in class file when the Form loads can any one give me an idea
My class file code is as follows
namespace ACHDAL
{
public class TansactionCode
{
string[] strTransactionCodes ={"20","21","22","23","24","25","26","27","28","29","30","31","32","33","34",
"35","36","37","38","39","41","42","43","44","46","47","48","49","51","52","53","54","55","56","80",
"81","82","83","84","85","86"};
}
}
Would like to load all th开发者_运维技巧ese in to the combo box when the Form loads if any thing has to be done in this code please let me know.
You populate combo boxes by setting their DataSource property (see here for more details on what you can bind to them).
To do this you'll need to expose the list first, so put it into a property. This is how the form will access it, after creating a new instance of the class.
public string[] TransactionCodes
{
get { return strTransactionCodes; }
set { strTransactionCodes = value; }
}
Then do this on the FormLoad event
eg
private void Form1_Load(object sender, EventArgs e)
{
TansactionCode trans = new TansactionCode(); // Create new instance
combobox.DataSource = trans.TransactionCodes; // Access the list property
}
精彩评论