简体   繁体   中英

DataGridView C# Help Required

This is my configuration for DataGridView.

 MySqlConnection mysqlCon = new MySqlConnection(Declare.connectionString);
 mysqlCon.Open();
 MySqlDataAdapter MyDA = new MySqlDataAdapter();         
 MyDA.SelectCommand = new MySqlCommand(sql, mysqlCon);
 DataTable table = new DataTable();
 MyDA.Fill(table);
 BindingSource bSource = new BindingSource();
 bSource.DataSource = table;
 dataGridView1.DataSource = bSource;

This works fine but i gotta use datagridview in many forms. Do I need to write this Configuration again and again.
How do you configure it once and use it many times.
Please Help
Thanks

You can create your own user control and use that in multiple forms. This way, all the common code will reside in a single location. Refer to this link to understand creating user controls in Windows forms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM