I'm doing a little application in order to understand how to manage menu options with different DataGridViews.
Here is a screenshot:
The form is divided using a SplitContainer, I use the left container for the menu and the right container for the DataGridView.
I also have a dataset with two tables, the DataGridView is currently associated with the "colors" table from the dataset. I can add, delete or modify the rows and then save the da开发者_如何学编程ta to the table without problems.
What I would like to do now is that when the "Shapes" button is selected, the DataGridView will be associated with the "Shapes" table from the dataset and the data in that table loaded in it.
The code behind the application:
namespace DataGridView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void colorsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.colorsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dataGridViewDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// This line of code loads data into the 'dataGridViewDataSet.Colors' table.
this.colorsTableAdapter.Fill(this.dataGridViewDataSet.Colors);
}
}
}
Any suggestions?
Well, simply add an event for click on your button (let's call it buttonShapes
). You will have a buttonShapes_Click()
method where you can reset your dataGridView and load your shapes data.
精彩评论