I have a datagridview control in winform. The datagrid view is extended to implement validating event of the grid. The problem is I have several buttons including button named ok in my form. But, I want to validating event to be fired in ok button click. How can I restrict validating event to be fired in ok button click.
Related
I am making an user interface from windows forms (c#).In my form there are many buttons named enable (for enable each textbox).What i need to do here is when the button relevant to textbox is clicked enable the textbox.(they are not in a groupBox). Without manually coding in each button click's method how can i do this in a programmatic way
Assuming you are trying to bind a textBox's enable property to a button, I would recommend you yo build a simple custom userConrol. Inside that control you will be able to bind the logic of the button to the TextBox. You can then add any number of that specific UserControl to your application and it will automaticly bind your button's logic to the textBox.
I am designing a form using C#.NET. Whenever a user selects a text field to fill out an event triggers that shows a picture corresponding to the field they are filling out. However, some users like to use the tab key to move through the form. When tabbing through the text fields, the event is not triggered and the picture does not show up. I need to know how to get .NET to trigger an event when a user uses the tab key to move into a field.
Any event with the word "Click" in it will generally only be fired by a mouse action which is why it is not being fired by the user using the tab key.
The Enter or GotFocus event will be fired by both the mouse and the keyboard when the cursor enters the control. Just create the _Enter event for your textbox and move your code into it.
If you want to remove the image when the textbox loses the cursor just use the _Leave event.
I have the next situation:
there is a client app with a Form
the Form contains a few TabControl's
there are different controls on TabPage's of TabControl's
when the user clicks on any control, I need to activate the TabPage that is a parent of a control. For that I use a TabPage Enter event
when the TabPage gets activated, I need to make request to the server app, and I put focus to a hidden TextBox to disable UI
The problem is, when I click on a Button on another TabPage, in TabPage.Enter event handler I take focus to my hidden TextBox, and it seems like Button click event doesn't have enough time to be processed. When I put timer and handle TabPage.Enter event after 100 ms, the Button click event seems to be fired well. Same thing happens to all the controls: CheckBox doesn't get checked, RadioButton too. I wouldn't like to use timer, as that is not a stable solution.
Any ideas how could I make TabPage to process all mouse events before I take focus to hidden TextBox? I tried to use Application.DoEvents(), but that didn't help.
You are using a wrong event for a wrong control for what you are trying to do.
Enter event for TabPage is going to be fired when that page becomes an active control of the current form which might not happen under certain conditions. Instead, you need to use Selecting or Selected event of TabControl, depending on whether you want to cancel switching to a different tab or not (see TabControlCancelEventArgs parameter of Selecting event). In your case, Selecting event would be more appropriate since it won't allow switching to a selected tab until event is complete (unless you're doing an asynchronous request to the server). Additionally, you may no longer need to use the hidden TextBox.
UPDATE
Regarding comments to OP, when you have 2 (or more) TabControls on a form and you want to get notified when you press a button in any tab of a different TabControl, you can use Enter event for TabControl. Use a global variable to store which TabControl was activated in the Enter event and then send server request for a currently active tab of that activate TabControl.
If this doesn't work for your scenario, then you need to carefully examine your workflow and see if it can be improved in relation to what you want to accomplish.
I have a grid which contains multiple columns/rows with ASP TextBox controls. In addition to this, above the grid I have a radio button list which contains years.
The user can enter numbers into the TextBoxes and then click an item on the RadioButton list to save the information then switch years or click an update button to just save the information and remain viewing the data.
If I click the 'save' button the textchanged event handler fires and I know what rows on my grid had something changed, then I update my DB and then get the data again to display to the user.
If however I click the radiobuttonlist to switch years the SelectedIndexChanged event fires but the TextChanged event handler does not run because the save and get data runs first, rebinding the grid and eventhandler.
This appears to me to be something to do with the way events run in .net, does anyone know how can I get the textchanged event handler to run first when clicking a radio button list?
I'm using VS2005, .Net 2.5, ASP.Net, C#
Thanks in advance
Your question is not clear. Anyway i can understand that you have problem with the event handlers and how they are called.
I want to know what is the need of calling the textchanged event and SelectedIndexChanged. Even they are not called your data would be get saved perfectly.
I have a gridview with a linkbutton inside a <HeaderTemplate>. There is an event handler for a click on this button. Now if I bind data to the gridview on every Page_Load event, then this event fires. But if I bind data to the gridview inside if (Page.IsPostBack == false), then this event doesn't fire.
Is it that after the pageload it realizes there is no data in the gridview hence ignore events generated from the grid?
How do I slove the problem ?
The LinkButton behaves like a Button
The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control.
That means it triggers a postback when clicked. So the only way to get the click event to fire, is to wire up the handler if Page.Postback=true. (Keep in mind that since HTTP is stateless, if you wire up an event handler on the initial page load, it won't "remember" upon postback.)