How to distinguish modified item in binding list? - c#

I am developing a windows application using C# and .net 4.5 under visual studio 2013 IDE.
In my application when the user attempt to enter a new data the program creates an object of appropriate class let's call the class DataClass and the to be objectOfDataClass.
The objectOfDataClass is added to a BindingList<DataClass> let it be bindingListOfDataClass which is bounded to a DataGridView as a data viewer.
The user enters data in a text boxes then he/she press a button to add text boxes value as a list item to bindingListOfDataClass and then he/she can view all data records on the DataGridView.
Then the user has a choice to click save button to save the data to a file or database.
All of these functions are working very well without any problem. But I want to add another function to mark or distinguish the new data entry or the modified cells on the datagridview and the bindingList by changing the style format of that cell (i.e: changing the background color or font style ..etc) before the user click the save button so he/she is notified to confirm any changes before saving the new entries.
The comparison should be between the saved data (the data on the file or database) and the data shown in the datgridveiw.
Now I am looking for a best solution which must achieves higher performance and preserve memory. so any suggestion please?

Exactly here you need to distinguish newly added items and already saved items
from the list So you can easily use flag for this....
When you click on Add Button you can false your flag & then true..Before items saved you can change color or something else where flag false..

Related

How to restore changed properties of a data binded object?

I'm stuck and I hope for suggestions. I'm talking about only in-memory objects. No databases or files involved here.
Basically I have an object whose properties I've bound to some text- and combo-boxes. When I change the value in a texbox, the value in the bound property gets also changed, obviously. What I want to achieve is, that when I change the value in a texbox, the change should be made only temporarily.
This is what I do:
I load my data and then the main form gets opened with a list of all my data items. I double click an item and another form gets opened where I bind the properties of the item to some textboxes. I change something and click cancel. Now if I open again the same item, the changes are still there.
I want the changes to be temporarily so only if I click save, then the item should be updated. I can't figure it out, how to do it with a data bound object. I guess I miss the point of Databinding?
I could make it easy by assigning the values of my item properties to the textboxes and write the values in the texboxes back to the item properties as I click save. But isn't Databinding made for this kind of work or am I completely off?
Should I query my database again to restore the original data of that specific Item, if I want to use Databinding?
Edit: As suggested in the comments, I can use a copy of the item and save its changes to the original item, as I click save. But what is a good way to enforce that the form is working with copies of that item only? The view should not need to know whether its a copy or not or that it should make a copy first.

c# combobox drop down click deletes everything in textbox

I have a windows program (.NET 4.5) that has a combobox with custom dropdown data. My autocomplete type is set to AppendSuggest, so that the customer can easily type in a name, press tab or enter, and then move on to the next box to fill in.
When the combobox loses focus (goes to another control), the program will parse the text in the textbox. If the name exists in the database, it will attach that person to this instance, otherwise it will create a new person with the name (properly cased) in the database.
Pressing tab allows the autocomplete box to fill in the remaining text and it successfully attaches it to the database. However, if the enter button is pressed or, more importantly, the customer tries to click on a user from the autocomplete drop down list, the textbox simply deletes all text in it and moves on to the next box with nothing in it.
I can't find out how to intercept the data that the user clicks. Ideally, I just want the user to click an item from the dropdown list and have it fill the text in, then parse that text and move on.
I have also checked my code and there is no where in the code that deletes the text from this combobox. It seems to be happening by itself behind the scenes.
Also, I am a somewhat advanced programmer in C#, and although I really haven't worked with autocomplete, I am baffled that I am stumped on something as simple as this.

How can I have a ComboBox retain the recently entered values?

I have a WinForms program in c# that features a text field that I would like to replace with an editable ComboBox.
The effect I would like to achieve is similar to the OpenFileDialog, or to some extent the Address bar in Windows Explorer. That is, when you enter in a valid item, that item is added to the list of possible values that the dropdown displays. I would also like this to persist on subsequent runs of the program.
So, basically
Program runs for the first time, ComboBox is blank and has nothing in the list
User enters a value into ComboBox and hits enter (or a button), value is used and then added to the ComboBox's list
User exits program
User re-enters program, ComboBox is blank but the value used in the previous session is in the list.
I can imagine several ways to implement this, but it just seems like something for which there might be an easy way to accomplish that I don't know about. Like how someone would implement autocomplete only to discover that the control supported it already.
If not then I can just go ahead with some other way of adding and persisting the information, I was just curious if there was something readymade already.
From the properties list of the comboBox you can choose the DropDownStyle as DropDown and from the Misc choose the autocompletemode to (suggest) or (appened).
when user enter something, it will be saved, and when he runs the app in the next time, you should fill the comboBox with the options or give a custom source from the misc too.

Advice on dynamically generating list

I'm new to coding in ASP, so your patience with me is appreciated.
I've built a user access request form which is working, however I now need to add a permissions section to it.
What this entails is 5 text boxes per row, but have it start with just one blank row, then if they fill in a row, another blank one appears below it.
Then when a button is clicked, the values are uploaded to my database.
This will also need to be populated if a user that already has access returns to the page.
Can this be done?
notes:
I'm using the EntityFramework, in .NET 4, with C#
maybe put a button to add new row

Check pending changes before doing a another task on a ASP.NET Ajax page

I'm developing an ASP.NET web application with AJAX.
I have a page where the user can edit some information: it has a list of item, the user select one item, click on Edit button and then edit item's name and item's description on two textboxes.
If user click on another item since he doesn't save his changes, he can click on edit button to edit this new item.
I want to check if there is some data on textboxes and ask to the user if he wants to lose their changes before loading the data of the new item.
How can I do that?
Thank you.
There are four ways that I can think of to handle this:
Always save the changes (auto save). We've eliminated almost all save buttons from forms and just always auto save the data based on user feedback.
Always prompt to save changes; i.e. assume that if the form is in edit mode then there are changes.
Hook every control's change event and toggle a boolean if any control fires its change event; prompt the user if it's true.
The hardest (and arguably best) method is to actually compare the previous values to the current values and only prompt if they're different.
The method you select depends on the application and user expectations.

Categories

Resources