C# - which event to populate a combobox before it's visible? - c#

I'm currently updating it on click, but this results in the user being able to see the repopulation occur. Which other event can I use which will allow me to handle it myself, then show the combobox when i'm ready? ( after population)

I don't know what you're developing, but that combobox is probably on a window or so that will have an event that fires on show. Use that event to populate the combobox in.
[edit] Ah Winforms. Use the Load event.
[edit2] On each click eh.
Alright. I found a dirty solutions that advises you to override the WndProc and capture messages, but I think it's better to inherit the combobox and override OnDropDown to perform you populating before calling the ancestor's OnDropDown method.
You should populate the box when entered too, because a value may be selected using the keyboard (arrows) without even dropping down the box. You'll need both if you want it on each selection, because a click only causes the Enter event when the box didn't have focus before.

Have you tried the ComboBox.DropDown Event?

You could try to call SuspendLayout() before updating and calling ResumeLayout() after the changes.

combobox.add_HandleCreated triggers after the control is created as the form is loading

Related

Event for "end edit" in a text box

I am using a textbox in winform (c#) and using the text to make consults in a database.
But I need constantly consult the text of the textbox every time that text changes. So for these, I use the KeyUp. But this event is too slow.
Is any event that just fires when the textbox editing has been finished ?. I consider for finish 2 conditions
The control lost focus.
The control has 200ms without keypress
You could use the LostFocus event, to capture when the user clicks on a control outside the textbox.
Otherwise, you'll need to choose from one of the existing events. (Listed here)
Come to think of it, you will likely have to capture multiple events. DragDrop if someone copies/pastes, for example...
You mean something like this?
Control.LostFocus
Provided that you consider finished as being when they click off the textbox.

WinForms ComboBox - Event when Text Input is Clicked Into

I have a feature request that when a ComboBox is 'clicked into' that it clears the text so that the user can start entering in new data to search. Does anyone know of a way to hook into this? The 'click' event is raised on when the text is clicked as well as when the drop down arrow is also clicked (which opens up the drop down with items). I only want it to happen on the first, not the latter.
Right now I'm capturing the click event and filtering on the DroppedDown property like so:
if(!comboBox.DroppedDown)
{
// clear selection
}
This seems to work most of the time, but bugs out frequently as well... so its not 100%.
If anyone knows of a proper way to do this I would appreciate!
Don't handle the click event. For one thing, it won't fire if the user tabs the focus into the control. Use the Enter event which fires when the control receives focus. And rather than clearing text you should just select it all which will give the best of both worlds:
1) The user can start entering new text which will clear any old text or
2) tab past the control and leave the contained text as it was.
If you always remove the previous text you may anger users.
Try the "Enter" event. It happens when a control gains focus on the form.

Cancelling TextChanged events (ASP.NET)

I have a bit of an issue with something I'm working on in ASP.NET/C#. I am using a GridView to display all 'items' linked to an account, with 3 fields relating to the link, but also all files not linked to it. Next to all records is a checkbox so they can link/unlink the two, and modify the 3 fields relating to that link.
I am currently using the 'CheckedChanged' and 'TextChanged' events to update the entries, as opposed to looping through each row in the Grid, checking its current state and updating accordingly etc which would provide a lot of overhead.
Problem is,the events fire if the user clicks a 'Cancel' button. Is there a way to detect if this certain button has been Clicked, and stop the events from firing? Or do you guys have better ideas?
First of all, it sounds like your Cancel button's Clicked handler is assigned to your custom function somewhere. By default it shouldn't do anything.
However, you can use the Sender object to check the type of object that fired the event:
if (sender is Checkbox) {
// Do something useful
}
I have not tested this code.

"press" edit button in gridview through c#

i'm doing a webshop in asp.net (c#).
Is there a way to push the edit button in the gridview through the code of c#?
I have a "new" button, that just adds the row, it would be great if that same row would "open" itself for editing without user having to press "new" then "edit"...
I know there are other ways to do this, i just want to know if this is possible... it would save tons of time!!
thanks in advance for the anwsers!!
Andrej
Just call the event handler you wrote to handle the edit button push.
Basically speaking, all that happens in code when you click a button is that the button's Clicked event is raised. In a GridView, the event is actually something like GridViewButtonClick. However many handlers you have plugged in will then execute (and you can't, and shouldn't have to, control the order of execution). For a built-in button, because you cannot raise the event from outside that button, you can simulate the button click by just calling the handlers you have attached to the event. If this were your own custom control, you could define a method you could call from outside that would cause the control to raise a certain event.

How do I trap a double-click event on a ListView that has no items?

In my C# app, I have a ListView on a Form. I want the user to be able to double-click on a section of the ListView when no items are selected in order to pop up a "New Item" dialog. The problem is that the DoubleClick event for the ListView only fires if an item is selected.
Is there a way to do this?
There is a way to do this, but you have to do some low-level drilling into the Windows machinery. It's generally not a good idea to spend a great deal of time trying to get a standard Windows control to behave in a non-standard manner.
A simpler way is to just put a "New Item" button next to your ListView. If screen real estate is an issue, you could just add an extra row at the bottom that says "{click here to add new item}", and show your dialog when the user clicks this last row.
Add an event handler for the List view's MouseDoubleClick event.
Assuming Windows Forms:
Perhaps a good workaround would be to use a ContextMenu.

Categories