Check if a DataGridView/BindSource have changed data - vb.net

I have a WinForms app with a datagridview and a bindingsource. I want the user to confirm changes before I save them to the database.
I don't want to pop up the confirmation dialog unless I know the user has made changes. So I need a way to check if changes have been made. Any suggestions?

You should be able to use BindingSource.ListChanged to rig a crude test - set a flag when the event is fired (you'll probably have to clear the flag once binding has completed).
But what is the data? For example, LINQ-to-SQL and DataTable both offer ways of querying for changes... (DataTable.GetChanges() and DataContext.GetChangeSet()). Most DAL-based mechanisms will usually have a way to do this too.

if you're (ultimately) binding to a datatable you can check the rowstate for Changed or Added

Related

Can Access ensure a new form record displays all fields?

I have a database where I don't want some fields showing depending on data in other fields. I'm still new to VBA, having learnt how to do things I need via the internet (there's not much call for it in my job so like to try it out on side projects) for the things I need and have managed to create some code that hides certain fields that aren't needed, depending on what's been entered in another field and that works okay, if not perfectly (I'd like it to only work on the current record and not all of them at once but will worry about that later). My problem is, if I'm entering information onto a record and any of those fields become invisible exactly as I would want them to, then if I have more records to complete and load a new record, those hidden fields are also hidden on the blank record before any data has been entered and I want each new record to show all fields from the outset.
Another thing I've noticed is that if I close the database, next time I go into it the hidden fields have unhidden themselves again so I know I'm missing something important.
Here's a screenshot of a bit of the code where I want 2 other fields (What_reason and Date_sent_to_new_owning_School) to be visible depending on whether the answer in the current field after update is "Standard" or "Non-standard":
I'm sorry if this is really entry-level stuff but I AM entry level and trying to learn. This bit does work, albeit not perfectly as I'd like it to only work on the record I'm in at the time, and not go through and hide that field in all the other records at once (which it's doing).
I've searched everywhere but can't find the answer and although I've tried, I'm nowhere near good enough at VBA to try and use common sense to work it out. Is this something that can be done? I'm okay with computers generally and with Access too but I'm aware there's an awful lot I don't know and this is why I'm trying to do new things and learn stuff that I've not used before. I have tried all day to get this to work but am admitting defeat and am hoping somebody here will be able to help me. I'll probably need 'idiot level' advice if that's possible, I know my limitations. :)
Do you know how to use the Event tab in the Property Sheet? You can set all of your fields to [field].Visible = True on either: On Current, On Load, or On Open
Screenshot of the Property Sheet and for the field that determines the visibility of all of the other fields; you can use the Event: After Update so that way when you click/tab away from that field, it'll make those changes for you!
Property setting affects ALL instances of control. Control will be visible/not visible for all records depending on conditions of current record. Therefore, dynamically hiding controls on form set in Continuous or Datasheet will NOT give the desired result of
only work on the current record and not all of them at once
Db is not going to 'remember' dynamic setting - code needs to be executed when form opens and/or navigating records - so it is needed in OnCurrent event as well as control's AfterUpdate.
Conditional Formatting can dynamically enable/disable textbox/combobox by record although control is still visible.

"Close" custom entity button

I've built a custom entity in Dynamics CRM. I'd like it to have functionality similar to the opportunity entity, Close as Won or Close as Lost, only this language would be Approved or Denied.
Approved button would set the status to "Approved" and make the entity read only.
Denied button would set the status to "Denied" and make the entity read only.
I've done some research and looked into ribbon workbench, but I've got no idea on how to actually make it lock the entity when the button is pressed. The only tutorial I've found makes it open a webpage, and I'm not sure how to hack that into doing what I want it to do.
Any suggestions or places to read up on how to do this? Thanks!
the request is a little bit generic. I'll try to help. First of all, when people "accept" or "denied" the new entity you created, do you want to deactivate the record? In crm when an opportunity is closed it becomes not editable because it's deactivated. To achieve that you should use the internal status, "active" or "Inactive". So you can catch the event with a plugin and set the status to disable/enabled.
You can managed this case client side too, you can read the field that you are setting as "enable/disable" and put all the fields on the form in read only.
The third option is to use a synchronous workflow, read a specific field, put a condition and change the status of the record based on that condition.
Whatever road you choose a little bit of work is involved :)
I think your question is fine. Instead of having the button open a webpage you can have it call a plugin (using javascript) which updates the instance of the entity that you are viewing. Intuitively it might make sense to just set your record to inactive when the "Denied" button is pressed which also has the side effect of disabling fields.
In this related post the second option is what I am referring to.

Detecting if user has made changes to FontDialog object

I've got a FontDialog box called aFontDialog.
Can I detect changes made to this dialog box?
Initially my object creates the dialog using this code aFontDialog.ShowDialog, the user than makes changes, then if the user is happy with their changes then the application will receive Windows.Forms.DialogResult.OK:
Is it possible to detect any changes made to this dialog by the user? Will I need to record the state of the different aspects of the dialog before and then compare to how they are after - or are there some properties or methods built into this dialog box that help me find any changes?
The most important concern here is - why do you need to know the changes. See, font is usually not a transactional object, so you normally don't need to avoid excessive network traffic or minimize number of database roundtrips.
I would just look if user pressed OK. If yes, set the new font, regardless of how similar it is to your current one. It's just one line of code - simple as assigning this new font to the old one:
Me.Font = MyFontDialog.Font 'Me could be any control in this case
Besides, I think it is your only way, if the font is different. Meaning you cannot for example set Font.Bold = True, because it's read-only. And it would not take a lot of processing time either, so no point in optimizing it.
If you really want to, you can examine FontDialog.Font after checking DialogResult for OK, and compare to what you passed there, although I don't see where this would be useful.

ASP.NET Keep fileupload after postback

I'm writing an intranet ASP.NET page using VB.NET. I've run into a particularly nasty problem dealing with handling file uploads. I'll do my best to explain the problem, and perhaps someone can help.
My problem is almost a duplicate of this one, or this one, except (other than the filename) I don't care about sending the file to the server until the other data has been reviewed.
Here's the situation:
Joe Q. Dataentry inputs some data into several fields. The first 3 are drop down, and when he changes the selection, a postback event is fired that queries a database for valid entries for the other drop down selections. After selecting the values, he inputs some other data, chooses a file to accompany the data and clicks the "Update" button. When he hits the button, it fires a postback event that sends the current data to the server to be validated. The data will create a change in the database, so he is presented with a view of the current state, and what it will look like when his changes are made. He can now either confirm or cancel the operation for whatever reason.
Part of the data he will see involves the extension of the file which may be a PDF, or could also be some image file or other document.
Now here's where my problem is - on each postback event, the fileupload dialog is cleared. I was getting around it by creating a temporary file on the first postback and then renaming if he clicks OK or deleting on Cancel... but I need to do a variety of things, based on the previous state of data and the filename. I've tried to keep some session variables to retain the filename, and that works OK for just renaming the file, but for what I need to do it gets unwieldy.
What I want to do is be able to have the postback event to present the changes, and then when the user clicks "OK", submit the file. Is there any possible way to do that?
One of my thoughts was to do some of the validation client-side (I'm already re-validating server side so I'm not too worried about data security there), but I don't know how I could get the information from the database query.
Thanks for any help, and reading my slightly convoluted story/situation!
EDIT:
It appears that what I want to do is prevent a certain button from firing a full postback. Is there any way to do that?
EDIT II:
I have an update panel on the page already - is there any way for the button to only post what's in the update panel?
What you might want to do is place your drop-downs inside of an ASP.NET AJAX UpdatePanel, and keep your file upload control out of that.
Your update panel will do the post backs and allow your validation logic to happen without submitting the file, then when you hit your final "Save" button (which is also outside of your UpdatePanel) the entire form will be submitted back and you can work with your file then.

Informing the user that a DataGridView is being populated

I am writing a program in VB.Net to manage text messages sent through an API. It allows you to view messages in a datagridview and filter by date, sent/unsent etc...
To load the messages I'm executing an SQL statement and retrieving a DataTable which then gets set as the DataSource for my DataGridView control.
The problem is that depending on the filters selected the user could be selecting a lot of records and it would take some time for the DataSource to update. I want to inform the user of this load time by providing a progress bar or label of some kind.
I have used progress bars before when looping through data but this is loading it all at once. I thought of displaying a label when the user clicks to load the data and then hiding it when the data is loaded. But this happens instantaneously even when the data is still loading.
Is there an event on the DataGridView I can use perhaps? Something like .DataSourceLoadStart and .DataSourceLoadFinished.
I know I'm just making those events up... but hopefully it makes it clearer as to what I want.
You could set the label to be visible when load is clicked and try the: DataGridView.DataBindingComplete Event to hide it, this event gets called when the binding is complete.
MSDN Link - DataBindingComplete
A little off topic but... I wonder if you could attach a AJAX update panel with activity/loading image to a gridview? I don't think I've ever seen it done but here's a great application for it.