I have a winforms application that has one tabcontrol with 2 pages.
On both pages I have data that is displayed in a datagridview called TaskTable. The data is displayed from TaskDataSet which is bound to an XML file.
However, at the moment the only way of displaying the data is to click the Read XML button so when the either of the pages are first clicked the datagridview is empty which I don’t like.
When the either of the pages are clicked I want the datagridview to automatically fill.
Any ideas how to do this:
Here is my code for the Read XML button if that helps:
private void ReadXmlButton_Click(object sender, EventArgs e) // event handler to display saved tasks.
{
if (TaskTable.Rows.Count == 0)
{
DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn(); // checkbox column = 'column'
{
column.HeaderText = "Complete";
column.Name = "Complete";
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
column.FlatStyle = FlatStyle.Standard;
column.ThreeState = false;
column.CellTemplate = new DataGridViewCheckBoxCell();
column.CellTemplate.Style.BackColor = Color.White;
column.CellTemplate.Style.ForeColor = Color.Green;
}
TaskTable.Columns.Insert(0, column); // Column of checkboxes.
TaskDataSet.Clear(); // Clears dataset
TaskDataSet.ReadXml(fileURL);
TaskTable.DataSource = TaskDataSet;
TaskTable.DataMember = "Task";
TaskTable.Columns[5].Visible = false; // hides numeric priority - only used for sorting
}
else
{
TaskDataSet.Clear(); // Clears dataset
TaskDataSet.ReadXml(fileURL); // reads xml to retrieve any additional tasks that have been added to the XML file.
TaskTable.DataSource = TaskDataSet;
TaskTable.DataMember = "Task";
TaskTable.Columns[5].Visible = false; // hides numeric priority - only used for sorting
}
}
Any help would be greatly appreciated!
Quick google search shows that the TabControl raises a number of events – the following probably being the most appropriate:
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.selected.aspx
hook up to that event and load your xml.