Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > "lazy" datagridview in usercontrol residing on non main TabPage
 

"lazy" datagridview in usercontrol residing on non main TabPage

how to prevent datagridview in a usercontrol residing on non mainTabPage from being "lazy"? lazy being zero rows until user clicks on the tabpage for the user control holding hte datagridview
fs - new to w7  Sunday, August 16, 2009 5:18 AM
thx. that works
So I have in Tabcontrol select

private void mainTabControl_Selecting(object sender, TabControlCancelEventArgs e)
{	// 090818 tested
	// make sure the test sample DGV is loaded
	if (e.TabPage.Text.Contains("Test Sample"))
	{
		if (ucTestSample == null) return;
		int iRowCur = 0;
		if (ucTestSample.getRowCnt() > 0) return;
		ucTestSample.showTestDataDGV(iRowCur);
		//addMsg("@debug mainTabControl_Selecting test sample rowcount" + ucTestSample.getRowCnt());
	}
}	// make sure the test sample DGV is loaded when Test Sample tab page is selected





In form load event
// note TestSampleTabpage is the non tabpage containign a user control with DGV

	this.TestSampleTabPage.Controls.Add(ucTestSample = new UserControlTestSample());

	//TestSampleTabPage.Select();  // don't ever run this line in form load or you may end<br/>		// end  with wierd display of the navigator with red jagged red lines
	//TestSampleTabPage.Show();  // not needed
	int idebugTSRowCnt = ucTestSample.getRowCnt();
	mainTabControl.Select();
In the User control
internal void showTestDataDGV(int idx){
	testSampleDataGridView.Show();
	if (idx <= 0) idx = 0;

	// not required for making DGV not lazy:
	bindingNavigatorPositionItem.Focus();
	bindingNavigatorPositionItem.Text = "" + (idx + 1);
}


fs - new to w7  Wednesday, August 19, 2009 4:03 PM
Handle the TabControl.Selecting event. Inspect the e parameter, and if it is switching to the tab with the DataGridView, set the DataSource (and possibly DataMember) property in that event (or otherwise load your data, etc.)
BinaryCoder  Monday, August 17, 2009 11:31 AM
thx. that works
So I have in Tabcontrol select

private void mainTabControl_Selecting(object sender, TabControlCancelEventArgs e)
{	// 090818 tested
	// make sure the test sample DGV is loaded
	if (e.TabPage.Text.Contains("Test Sample"))
	{
		if (ucTestSample == null) return;
		int iRowCur = 0;
		if (ucTestSample.getRowCnt() > 0) return;
		ucTestSample.showTestDataDGV(iRowCur);
		//addMsg("@debug mainTabControl_Selecting test sample rowcount" + ucTestSample.getRowCnt());
	}
}	// make sure the test sample DGV is loaded when Test Sample tab page is selected





In form load event
// note TestSampleTabpage is the non tabpage containign a user control with DGV

	this.TestSampleTabPage.Controls.Add(ucTestSample = new UserControlTestSample());

	//TestSampleTabPage.Select();  // don't ever run this line in form load or you may end<br/>		// end  with wierd display of the navigator with red jagged red lines
	//TestSampleTabPage.Show();  // not needed
	int idebugTSRowCnt = ucTestSample.getRowCnt();
	mainTabControl.Select();
In the User control
internal void showTestDataDGV(int idx){
	testSampleDataGridView.Show();
	if (idx <= 0) idx = 0;

	// not required for making DGV not lazy:
	bindingNavigatorPositionItem.Focus();
	bindingNavigatorPositionItem.Text = "" + (idx + 1);
}


fs - new to w7  Wednesday, August 19, 2009 4:03 PM

You can use google to search for other answers

Custom Search

More Threads

• BindingManagerBase Deletion is Final?
• How to connect to secure database
• Checked Status DataGridViewCheckBox
• Passing GUID as parameter to an Insert Query - invalid conversion to string
• I have to remove a databinding at runtime
• TableAdapter SQL
• Datagridview unbound computed on bound...which event to use?
• Trying to get a ComboBox to set a value to the currently selected index
• Data Source Configuration Wizard Error
• How do i delete rows in a datagrid?