I'm writing an app where you can input a lot of data in a lot of different controls (textboxes, updowns, etc.)
Now I want to implement a function you see in most other apps where you input information and save it: the moment the user changes a saved file or inputs something into a new file, the file is unsaved and upon closing it, the user will be prompted if he wants to save changes.
The only way I can think of to achieve this is to use each input control's change event (change text for textbox, change value for UpDown, etc.) and set an "unsaved" bool to true.
When the user wants to exit the app, check the bool and display a message box if necessary.
Is there an easier way other than using all the events (I have a lot of data, so that would be about half the code of each form or more)?
Yea, the most obvious solution is the tedious one: trap each input control's change event and set an isDirty type flag for the form to true.
But... you could think of this as a more general-purpose problem too. It wouldn't be difficult to write a separate controller class - one that could take a form as input, loop through all of its controls, and assign event handlers for the input control change events. This controller would have an Initialize(Form frm) method and an IsDirty read/write property. You would then instantiate this controller in the Load event for each winForm you wish to track this way. When you save a document from the winForm, you set the controller's IsDirty flag to false. Then whenever the input changes on the form, the controller has already established event handlers that sets its IsDirty flag to true.
Once the controller class is built, it becomes very simple to use in your winForm and reusable across multiple forms.
For a system (similar to a Windows Service) I wrote a while back I had to write an editor for its configuration. The editor had to alert the running process of any saved changed. I didn't want false-positives (e.g. changing a value from 2 to 3 and back to 2), so as to avoid interupting the process needlessly. It wasn't much data so I had it save a copy of the data it read in. At exit it compared the two copies and only saved and alerted if there were actual changes.
I realize this may not apply to your current situation, but maybe it'll help someone else someday.
This[^] is one way of implementing it that I've come across. It's old code, and some of what it uses is marked as obselete, but may be a starting point.
It would be very useful if System.Windows.Forms.Control had an IsDirty read only property and an IsDirtyChanced event, then it would cascade through to every control we use, and would automatically be there in any new controls we create.
Dave BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
I think you need to just set Scrollable=True only. RightToLet Property is used for "Gets or sets a value indicating whether listviews elements are aligned for right-to-left fonts"
Please Read the MSDN Documents on Same.
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.
Hope you are all doing well. I have a question that I just can't seem to find a good answer to. I am trying to use WIA to scan multiple documents without user interaction. I found out how to call the camera and scanner wizard to acquire images from the scanner and it does allow for document feed.
So this all works well and good. The only problem is that my application needs to know where they selected the files to go so that I can send them to the database when they are done. I just can't figure out how to get that location from the wizard. Can someone please lead me in the right direction here, or at least tell me if this is possible with the ShowAcquisitionWizard method?
I have a bound datagridview which contains three combobox columns. The items in each combobox is databound also but dynamically. Depending on the value of the first combobox, the second and thrid combobox will be bound accordingly. I subscribe to the cellendedit event where I check if the cell is in the first column and then databind the second and third combobox cells accordingly. This works fine. The only problem I have is that when the datagrid view is loaded, as it is databound it is trying to assign the second and third cells of each row values which is not in their respective combobox list as the combobox is not bound. Is there any event available in the datagridview control which will let me check the value just before it is being bound to the datagridview cell. There I can bind the comboboxes before the value get's assigned and I shouldn't get any problems. I tried using the databinding complete but that didn't work.. Any suggestions?
Whilst on the subject of painting, for what you are trying to to do you do not need to override the OnPaint() method, simply handle the Paint event of your form.
As far as moving the points is concerned the procedure will be the same as moving any drawing object.
1) Handle the MouseDown event, in it decide if the mouse location (e.Location) is at a point of interest. If so, make a note of the point1 and then set a boolean flag to true (call the flag something like 'moving' so that its name reminds you of what it's for, and take a note of the current position of the mouse in a class scope field (it will be needed in several places), of type Point, something like this.moveStartPoint = e.Location.
2) Handle the MouseUp event, in it set the flag ('moving') to false, and the moveStartPoint to null and call this.Invalidate()
3) Handle the MouseMove event, in it first check that 'moving' is true (this means that the mouse is still down). If not return. If it is true then set the point that you made a note of in 1)1 to the new location of the mouse. As you are only moving a point you can set it directly but if you were moving a 'shape' fro example, you would have to use something like
storedPoint.X += (e.X - this.moveStartPoint.X);
Take a look at this[^], for a complete example of moving things you have drawn.
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I am currently developing a CAN-Monitor (Controller Area Network). The messages
are received event-driven. At the moment the display of the messages is done by a ListView.
In the near future the number of received messages will grow up to ~ 600-800 messages per second.
The messages (encapsulated in a specific object) are delivered to the view via event to a event-handler-method.
Is there a alternative to the ListView which is more performant than the standard-one?
The ListBox, but whatever control you use, as a user I can't read 600/800 messages per second. What's in the message that it needs to be displayed? If there's no specific information, I'd show a label saying (done msg x of y), and only show those who are "interesting" enough.
Even if there was such a control, how would a person make sense of a list that was constantly adding messages at an average rate of 700/sec? That sounds like the definition of information overload to me; I'd be more concerned with reducing the amount of information inserted into the list rather than finding a better list control.