C# .NET - Block Tab Changing TabControl

Asked By Gerry H.
18-Nov-09 04:55 PM

Hello again.... back with more Q's jejeje xD...

How can I block  changing tabs from a TabControl Vb.NET , so the user is obligated to use a navigation panel.... setting enabled property to false  for each tab when user click a button is done, but makes the code very large.... i´m talking about 13 tabs, so if anyone knows a small func for blockin all click events on tabs i´ll be very gratefull---

 

 

tnx!! all

 

Why would you want to do this?  Why would you want to do this?

23-Nov-09 09:34 AM

It is standard UI functionality that if you show a Tab, user's can click on it.  You will confuse your users by making the Tab visible but not allowing them to use it.

Depending on the control, you can usually trap the Tab click and Tab mouseup/mousedown events.  Keep track of the currently selected Tab index that is valid.  Subsequent attempts to change tabs via the click event or mouse events should call a method that determines whether you want to allow the change or not.  If not, reset the selected Tab index to your last valid Tab index.

  Chris replied to Gerry H.
06-Apr-10 12:15 PM
If you are using .net framework 2.0 or above it is really simple, even easier than the firs respondent explained it.  The TabControl has an event called Deselection with a TabControlCancelEventArgs as one of it's parameters.  The TabControlCancelEventArgs has an attribute called cancel.  In this event check for the conditions under which you do not want the user to be able to change tabs.  If they are met simply set the cancel attribute to true otherwise do nothing.

Example (in vb.net should be very similar in c#)

Private Sub TabControl1_Deselecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Deselecting

     If myCondition Then
          e.Cancel = True
     End If
End Sub

I hope this helps
Create New Account
help
encountered an exception when trying to access the setup state file: Could not find file 'C: \ ExchangeSetupLogs \ exchangeInstallState.xml'. [11 / 17 / 2011 19:11:40.0020] [0] Setup is determining what bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:14:14.0386] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreConfiguration-20111117-13141306991562273802.ps1' [11 / 17 / 2011 19:14:14.0386] [1] Executing 0417] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0550] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreSetup-20111117-13152805501269886028.ps1' [11 / 17 / 2011 19:15:28.0550] [1] Executing 0550] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0706] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreFileCopy-20111117-13152807061586562721.ps1' [11 / 17 / 2011 19:15:28.0706] [1] Executing 0706] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleTargetVersion = '14.01.0339.001 1340, MSExchangeADTopologyService, 1484, msftesql, 1532, svchost, 1552, SMSvcHost, 1576, Setup, D: \ Setup.EXE 1576, Setup, C: \ Windows \ SYSTEM32 \ ntdll.dll 1576, Setup, C: \ Windows \ system32 \ kernel32.dll 1576, Setup, C: \ Windows
encountered an exception when trying to access the setup state file: Could not find file 'C: \ ExchangeSetupLogs \ exchangeInstallState.xml'. [11 / 17 / 2011 19:11:40.0020] [0] Setup is determining what bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:14:14.0386] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreConfiguration-20111117-13141306991562273802.ps1' [11 / 17 / 2011 19:14:14.0386] [1] Executing 0417] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:14:14.0417] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0550] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreSetup-20111117-13152805501269886028.ps1' [11 / 17 / 2011 19:15:28.0550] [1] Executing 0550] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0565] [1] Executing: $RoleTargetVersion = '14.01.0339.001 bin \ EnterpriseServiceEndpointsConfig.xml". [11 / 17 / 2011 19:15:28.0706] [1] Writing informational script to 'C: \ ExchangeSetupLogs \ Start-PreFileCopy-20111117-13152807061586562721.ps1' [11 / 17 / 2011 19:15:28.0706] [1] Executing 0706] [1] Executing: $RoleRoles = 'ClientAccessRole' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleSetupLoggingPath = 'C: \ ExchangeSetupLogs' [11 / 17 / 2011 19:15:28.0706] [1] Executing: $RoleTargetVersion = '14.01.0339.001 1340, MSExchangeADTopologyService, 1484, msftesql, 1532, svchost, 1552, SMSvcHost, 1576, Setup, D: \ Setup.EXE 1576, Setup, C: \ Windows \ SYSTEM32 \ ntdll.dll 1576, Setup, C: \ Windows \ system32 \ kernel32.dll 1576, Setup, C: \ Windows
Text = = "All" && CheckBoxList1.SelectedIndex = = -1) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and c.city_id = d.city and a.prop_name = d.prop_name and e.ownership_id = d.prop_ownership and prop_type CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and c.city_id = d.city and a.prop_name = d.prop_name and e.ownership_id = d.prop_ownership and prop_ownership CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and
Text = = "All" && CheckBoxList1.SelectedIndex = = -1) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and c.city_id = d.city and a.prop_name = d.prop_name and e.ownership_id = d.prop_ownership" , con); } else CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and c.city_id = d.city and a.prop_name = d.prop_name and e.ownership_id = d.prop_ownership and prop_ownership CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d.carpet_area, d.bedrooms, d.prop_desc, e.ownership_name from tbl_image_entry a, tbl_state_new b, tbl_city_new c, tbl_new_sale_property d, tbl_ownership_master e where a.user_id = d.user_id and b.state_id = d.state and