c# - Can't get desired tabPage & form to display on startup -
revising question ask why after finding offending line trial , error. hints answers suggested occurring after form load. found line setting tabcontrol1.selectedindex = 1; tabpage2 index 1 why wasn't selecting tabpage2? after changing 1 0 displays correctly.
i can't find white paper or tutorial on tabcontrol , use of selectedindex can tell me how works?
private void form1_load(object sender, eventargs e) { getregions(); tabcontrol1.selectedindex = 1;
i have windows form had 10 tabpages on tabcontrol1. change in requirement necessitated except 2 & 8. prior removing tabpages, tabpage2 , form displayed @ startup. can remove 3,4,5,6,7,9,10 without problem (1,2,8 left). if remove tabpage1 tabpage , form displays @ startup tabpage8. tabpage2 , stay way.
i've played on , off couple of weeks , stumped. can't seem find article or question describing this. found multiple suggestions add this.tabcontrol1.selectedtab = tabpage2; doesn't seem anything.
what might causing , need do? (don't know code need paste, let me know if more needed)
// tabcontrol1 // this.tabcontrol1.anchor = ((system.windows.forms.anchorstyles)((((system.windows.forms.anchorstyles.top | system.windows.forms.anchorstyles.bottom) | system.windows.forms.anchorstyles.left) | system.windows.forms.anchorstyles.right))); this.tabcontrol1.controls.add(this.tabpage2); this.tabcontrol1.controls.add(this.tabpage8); this.tabcontrol1.location = new system.drawing.point(13, 27); this.tabcontrol1.name = "tabcontrol1"; this.tabcontrol1.selectedindex = 1; this.tabcontrol1.size = new system.drawing.size(963, 483); this.tabcontrol1.tabindex = 1; this.tabcontrol1.selectedtab = tabpage2; // tabpage1 // this.tabpage1.location = new system.drawing.point(4, 22); this.tabpage1.name = "tabpage1"; this.tabpage1.padding = new system.windows.forms.padding(3); this.tabpage1.size = new system.drawing.size(955, 457); this.tabpage1.tabindex = 0; this.tabpage1.text = "region overall status"; this.tabpage1.usevisualstylebackcolor = true; // // tabpage2 // this.tabpage2.controls.add(this.lstbuildlist); this.tabpage2.controls.add(this.label9); this.tabpage2.controls.add(this.label8); this.tabpage2.controls.add(this.lblfilelookup); this.tabpage2.controls.add(this.btnfilelookup); this.tabpage2.controls.add(this.cbregion); this.tabpage2.controls.add(this.tabcontrol2); this.tabpage2.controls.add(this.tvfileman); this.tabpage2.controls.add(this.txtfilelookup); this.tabpage2.controls.add(this.cbregionsites); this.tabpage2.location = new system.drawing.point(4, 22); this.tabpage2.name = "tabpage2"; this.tabpage2.padding = new system.windows.forms.padding(3); this.tabpage2.size = new system.drawing.size(955, 457); this.tabpage2.tabindex = 1; this.tabpage2.text = "build attribute maps vista files"; this.tabpage2.usevisualstylebackcolor = true; this.tabpage2.click += new system.eventhandler(this.tabpage2_click); // tabpage8 // this.tabpage8.location = new system.drawing.point(4, 22); this.tabpage8.name = "tabpage8"; this.tabpage8.padding = new system.windows.forms.padding(3); this.tabpage8.size = new system.drawing.size(955, 457); this.tabpage8.tabindex = 0; this.tabpage8.text = "edit attribute map/ create sql tables attribute map"; this.tabpage8.usevisualstylebackcolor = true; this.tabpage8.click += new system.eventhandler(this.tabpage8_click); this.tabcontrol1.selectedtab = tabpage2; //
you can select tabpage after initializecomponent or @ form_load display @ startup.
here's sample code have tested
namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); //select tabpage after initialize tabcontrol1.selectedtab = tabpage3; } private void form1_load(object sender, eventargs e) { //you can select @ form load or @ other action button click //tabcontrol1.selectedtab = tabpage3; } } }
don't write code @ designer. write after initializecomponent call.
Comments
Post a Comment