C#中Winform中跨界面combobox控件绑定问题
发布网友
发布时间:2022-04-30 05:29
我来回答
共2个回答
热心网友
时间:2022-04-10 11:25
其实就是标间传参,这里提供给你2中方法
1.窗体初始化的时候写构造函数传值过去
2.利用委托触发自定义事件通过自定义eventArgs传过去
3.全局变量(不推荐)
热心网友
时间:2022-04-10 12:43
private void Form1_Load(object sender, System.EventArgs e)
{
// Set the connection and sql strings
// assumes your mdb file is in your root
string connString = @"Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb";
string sqlString = "SELECT * FROM customers";
// Connection object
OleDbConnection connection = new OleDbConnection(connString);
// Create data adapter object
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sqlString, connection);
// Create a dataset object and fill with data using data adapter's Fill method
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "customers");
// Attach dataset's DefaultView to the combobox
listBox1.DataSource = dataSet.Tables["customers"].DefaultView;
listBox1.DisplayMember = "CustomerID";
// Attach dataset's DefaultView to the combobox
comboBox1.DataSource = dataSet.Tables["customers"].DefaultView;
comboBox1.DisplayMember = "CustomerID";
}
参考资料:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c43c.aspx#q561q