groupboxes becomes inaccessible using TAB after clicking button - c#

I have a form which has two groupboxes (& other controls as well, its the groupboxes that are creating problems), a 'SAVE' button which saves the form data into a database & a 'NEW FORM' button which resets the form (ex. txtName.clear(); rbCash.checked = false). The groupboxes have a couple of radio buttons & have tabindex's set.
Now, an user has to first click on the 'NEW FORM' button to activate the form. User can move through the controls using TAB. Then, the user clicks on the SAVE button to save the form.
Now, the user can move through the groupboxes using TAB only before he clicks the 'SAVE' button. After he clicks the 'SAVE' button & then the 'NEW FORM' button & tries to move through the controls using TAB everything receives focus except the groupboxes & the radiobuttons inside it.
any suggestions why am facing this problem??
oh.. one more thing. All the form controls (including the groupboxes) are inside a very big parent groupbox which gets disabled on clicking the 'SAVE' button & is enabled again when user clicks on 'NEW FORM' button. When the application starts the parent groupbox is disabled. Clicking the 'NEW FORM' button enables this parent groupbox & all the child elements within it to be enabled.
help please..

You have to be sure that the boxes have
TabStop = true
If you are programming in Visual Studio also the tool under View->TabOrder can be useful (see here)

Related

How to add multiple tabs or pages in Win forms Application

This is UI of the app which I'm creating, So if a user clicks Home button he should be able to play with some specific controls and again if he presses Sellers button, new tools and controls should be visible on the screen!
I tried to implement this by using 4 panels with
panel_name.visible=false
in respective button click event, but the problem is each panel should take up 1/4th of the space in the form to display all of its respective tools.This makes the panel area too small!
How can I make the application such that If a user clicks Home button, he should see one page/tab and different tabs/pages for different buttons clicks?
I suggest you use the user controls: right click on your solution> add> user control
C# UserControl
How to create and use UserControl
The user controls are similar to the forms, since you can place controls on them, the difference is that instead of showing them as common forms, you drag them as a control inside the form

Buttons changing Tabs

I want to make buttons change Tabs but i want the tabcontrol to be invisible (Only the page visible not the tabcontrol buttons).
I have 2 buttons Home and Settings and when the Form starts the Home page is visible and when the user clicks Settings button it changes to the Settings page and the same goes for Home button.
So what i need is for the Home and Settings tab buttons to be invisible and i want to only be able to use the buttons i created to change the pages. Hope someone understands. I use Visual Studio 2015 and C#.
Going by the name of your control (TabControl1) I am assuming this is WinForms.
You can achieve what you are describing without using a tab control at all, just move the contents of each of your tabs to seperate UserControls and then swap the visibility or positioning (or both) upon each button click.
For Home button click handler:
settingsUserControl.Visible = false;
homeUserControl.Visible = true;
Then repeat the reverse, in the Settings button click handler.
If you are using TabControl for its border, then use a Panel as a container to the UserControls.
In fact, this is similar to how Tab Controls worked in VB6, the control being hidden would be shoved 30,000 Twips off to the left, outside the view port of the tab control.

passing data from Ajax Modal popup extender to a textbox on the asp.net page

I have a Ajax modal popup that displays a set of options for the user. On submit button click event on the ajax modal popup, i need to pass the user selected data back to a text box on the user control (which has the modal pop up) on the calling page.
Structure/flow is as follows. There is a page and two user controls. One is a search control that has another user control that contains the user options. The master page has the search user control. When the user chooses an option in a dropdownlist in the search control, it does a mpe.Show of the user control with options. User makes his selections and hit submit button. In the button click event in the popup, i delegate an event back to the search user control which tries to set the value in one of its text boxes. Everything is going fine until this step and i can see the value but the text box never changes. It seems like the user control is already rendered and the changes are ignored. Any idea how I can get around this?
In short, how to get back the data to a control from an Ajax modal popup.
Use jquery - when the user clicks a button on the modal - use jquery to set the value field to be the data that the user has selected.
e.g.
$('#modalButton').click(function() {
var userData = $('#tbUserData').val();
$('#textBoxElsewhere').val(userData);
});
for anybody's future reference, i did a work around for this. What was happening is that, on the final button click postback, the page/parent user control load events run first and then the button click event.. so the changes that were being made in the button click event did not make it back to the parent user control on the page.. i had to add a middle step to display the user selections for approval and force the user to hit a final confirmation hit. On that post back, the changes were already available for the parent user control, and not have to wait for the button click event to trigger to grab the data. I'm sure there is a better way to do this but this is what I could come up with.

Windows Form Tabs switching

I have three tabs in a Windows Forms tab control. Currently in Tab1 I have a button that saves the information in a textbox and automatically changes the tabcontrol.SelectedIndex to Tab2. Tab2 then uses the information saved from tab1's textbox.
I want a messagebox to popup whenever the user changes the textbox in tab1, but then manually clicks tab2 or tab3 without hitting the button to save the information.
So in summary, I have it so clicking a button on tab1 automatically sends it to tab2. I want a messagebox to pop up if the button on tab1 is not pressed when the information was changed and the user manually changed the tab.
I think a wizard-like design for your application is more appropriate. Tabs are not supposed to work like that from a user's perspective.
But a workaround for your current situation is:
declare a variable, for example dirty
set this variable whenever any control in tab1 has been edited
clear the variable if the button in tab1 is clicked
check this if tab2 or tab3 is selected
You can use the Deselecting event on the TabControl to be informed when the selected tab is changing. If the tab that is being deselected is the tab with the button on it and the information is not saved, you can display the message box.
Also, depending on what your program does, it may make more sense to go ahead and save the information when the tab changes without even bothering the user.

Buttons Are Automatically Selected (how to turn this off?)

I have winform buttons that when you load the form, a certain button is selected. What I mean by selected, is that if "enter" is pressed, the button is pressed.
How can I change my buttons so they don't do this anymore?
Your tab order is set in the order in which you add controls on the form. If your first control which can be pressed/selected/edited is that button which is getting pressed, the focus will automatically be on it when form is loaded.
You can cheat by setting the focus to some other control (maybe which is not visible? !hint * hint!) to avoid the button to be selected at first.
But also make sure tht button is not the AcceptButton of the form.
Two concepts have been touched on by Nayan and rerun:
1) AcceptButton
2) Tab order
There is one more I would add and then try to explain how the three things relate:
3) Focus
Focus means that a child control has the "keyboard focus". When a control has focus, it receives keyboard input and can respond to it. Focus is changed either by clicking a control with the mouse, or by using the Tab key.
Tab order is the order in which controls receive focus when the Tab key is pressed. It also determains which control initially gets focus (the first one in tab order).
The AcceptButton concept is a bit of a hybred. If a form's AcceptButton property is set to a button control, that button is pressed when the user presses the Enter key while focus is on any control that does not process the enter key itself. Typically the 'Ok' button on a form is set as the AcceptButton so that the user can enter data and press Enter as a shortcut to pressing the Ok button.
You need to set the acceptbutton on the form.
Element.Select() is what worked for me.

Categories