Click here to Skip to main content
15,885,757 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting images from a browser Pin
Anthony Mushrow25-Nov-07 3:14
professionalAnthony Mushrow25-Nov-07 3:14 
GeneralRe: Getting images from a browser Pin
aj.esler25-Nov-07 12:20
aj.esler25-Nov-07 12:20 
QuestionGet color of a string Pin
shehezada25-Nov-07 0:02
shehezada25-Nov-07 0:02 
AnswerRe: Get color of a string Pin
Luc Pattyn25-Nov-07 0:09
sitebuilderLuc Pattyn25-Nov-07 0:09 
GeneralRe: Get color of a string Pin
shehezada25-Nov-07 0:38
shehezada25-Nov-07 0:38 
QuestionDataGridView - how to delete Row Pin
A.Asif24-Nov-07 23:39
A.Asif24-Nov-07 23:39 
AnswerRe: DataGridView - how to delete Row Pin
Aftab Sindhi25-Nov-07 21:09
Aftab Sindhi25-Nov-07 21:09 
QuestionHelp Needed. DataBinding in Windows Forms Pin
Aftab Sindhi24-Nov-07 20:35
Aftab Sindhi24-Nov-07 20:35 
1st of all, let me tell you that I am new to Windows (Desktop) Applications. I am basically ASP.NET developer and have worked much in this field. Now I am trying to work on windows applications and facing lot of challenges. One of which is described below.

IF YOU HAVE NOT ENOUGH TIME TO READ THIS ALL, JUST GO TO THE END AND READ MY QUESTIONS IN A FEW LINES. This may not clear, why I need this.

Goal
-----
Create the window for data input. On Ok, record should be entered in data set On Cancel, record should be discarded. User can enter as many records as required and also can update some existing records. By navigating to each records, user can cancel the changes of each record. To commit the changes, user have to click Save button. To reject the changes, user have to reload all data.

Design
-------
I am working on C# project. I've created the Typed data set. Windows form is populated with required controls (Text Box, Check Box only for my current window), one Binding Source control bound to the table of Data Set (Which automatically created Table Adapter for me. I've bound the form controls (Text Boxes) to the Binding Source's properties (Automatically created by designer). I've also created navigation controls manually.

Run time behavior
------------------
Some records already exist in the database, so when Application is run, records are automatically displayed in the controls(by fact they are bound). Navigation controls(Next,Previous,First & Last including the record position and total records) are working properly and displayed contents are changed properly.

Problems
---------
1. How I can add new record?
Binding Source's Add method requires parameter as object to be inserted. What object I can pass? and how to get / construct that object?
Binding Source's AddNew() method is working (NOTE: I am calling AddNew method of the BindingSource in a method, where I initialize all the controls(texboxes) of the form(record) to initial values. TextBoxes are also assigned Empty string). Record pointer & navigation controls are updated. At this level, It seems everything is ok. When Add New button is clicked (To add an other new record) exception is thrown saying [columnname] do not allow null value.
To overcome this, I changed the way to enter the new record. Now I enter the new row directly to the DataTable in the dataset, rather than adding to the Binding Source by calling its AddNew() method. After adding I change the position of the Binding source to the last record of the data table. The problem with this is, the row is already entered by bypassing some business rules (validations).

How I can cancel the changes of each record ?
-----------------------------------------------
On the cancel, I am checking the row state of the displayed record (current record). If its new (Added), i am simply deleting the record. This is working.
When I navigate to the existing record, and I change some values in text boxes, and then try to Cancel the changes. Nothing is changed? (old values are not shown in controls). I put the condition to check, On Cancel click, if current record's row sate is Modified, I am calling CancelEdit() method of the Binding source (Same buttons Added state is handled correctly as i mentioned above). While debugging, I encountered that some times row sate is shown Detached and some times Modified. I put both conditions with OR (||) operator, surely CancelEdit() method is called but still control is displaying new values (means changes are not reverted at control level). I tried to call EndEdit() method of current row, Before and after CancelEdit, but still no luck.

One more thing, on FormClosing event of the window, i am checking if any changes were made to the records and ask from the user Yes=Save,No=Discard,Cancel=Dont close the window. After editing a text box and trying to close the window, doesn't display the dialog box to ask. Why changes were not made to the Table in Dataset?

Let me confess that, while working on this, I canceled the new added rows, which I mentioned above that its working fine. I didn't try to save new added rows. so I don't know while saving, it'll throw any exception or not.

phewwwwwww!!!!

Summary of the problem and help needed
----------------------------------------
Is there easy way to add/update records with cancel (changes) functionality in Windows forms? Note that there are many fields/columns, so Its not preferred to use Data Grid.
How to cancel changes of the updated record by using Binding Source ?
Am I going to wrong direction ?

Regards
Questionfilling and retrieving tables Pin
sajid.salim.khan24-Nov-07 20:31
sajid.salim.khan24-Nov-07 20:31 
AnswerRe: filling and retrieving tables Pin
Aftab Sindhi24-Nov-07 20:41
Aftab Sindhi24-Nov-07 20:41 
GeneralRe: filling and retrieving tables Pin
sajid.salim.khan24-Nov-07 20:52
sajid.salim.khan24-Nov-07 20:52 
GeneralRe: filling and retrieving tables Pin
Aftab Sindhi24-Nov-07 21:05
Aftab Sindhi24-Nov-07 21:05 
QuestionUpdate 2 related froms on closing one of them Pin
Shaahinm24-Nov-07 20:08
Shaahinm24-Nov-07 20:08 
AnswerRe: Update 2 related froms on closing one of them Pin
Aftab Sindhi24-Nov-07 20:48
Aftab Sindhi24-Nov-07 20:48 
GeneralRe: Update 2 related froms on closing one of them Pin
Shaahinm24-Nov-07 22:57
Shaahinm24-Nov-07 22:57 
QuestionLINQ Pin
CataclysmicQuantum24-Nov-07 19:34
CataclysmicQuantum24-Nov-07 19:34 
AnswerRe: LINQ Pin
Christian Graus24-Nov-07 23:14
protectorChristian Graus24-Nov-07 23:14 
QuestionStored Procedure in a RichTextBox Pin
shehezada24-Nov-07 19:26
shehezada24-Nov-07 19:26 
AnswerRe: Stored Procedure in a RichTextBox Pin
mav.northwind24-Nov-07 20:04
mav.northwind24-Nov-07 20:04 
GeneralRe: Stored Procedure in a RichTextBox Pin
shehezada24-Nov-07 20:51
shehezada24-Nov-07 20:51 
GeneralRe: Stored Procedure in a RichTextBox Pin
mav.northwind25-Nov-07 1:04
mav.northwind25-Nov-07 1:04 
Questioncombo+sql+C# Pin
sajid.salim.khan24-Nov-07 19:21
sajid.salim.khan24-Nov-07 19:21 
AnswerRe: combo+sql+C# Pin
Aftab Sindhi24-Nov-07 20:55
Aftab Sindhi24-Nov-07 20:55 
QuestionC# String Function (IsPrintable/IsUnicode/etc) Pin
Jeffrey Walton24-Nov-07 19:20
Jeffrey Walton24-Nov-07 19:20 
AnswerRe: C# String Function (IsPrintable/IsUnicode/etc) Pin
mav.northwind24-Nov-07 20:10
mav.northwind24-Nov-07 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.