|
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
|
|
|
|
|
i have to fill SQl 2000 tables from window forms the problem is when filling the 1st table i load the database table in a datset in the form load event now when filling the second table what will be the possible event to fire that it load the second table in the datset
sas
|
|
|
|
|
I think its not clear what you exactly need. I am sorry at least for me, its not clear. Would you like to explain please ?
|
|
|
|
|
sir the problem is i am working on a HR database u have worked on web forms the application consists of 4 forms every form is associated with two tables in sql2000 the question is that when the user open the application in the form load event i kept the dataset filling method for the first table now when user switch on to the next table what will be the event to load the second datatable in the datset
sas
|
|
|
|
|
well sorry to say dear Sajid, you've failed to describe your problem. HOW?
1st of all, you are talking about the FORMS of the application, on other hand you are talking about switching to next TABLE
I think there is no any TABLE control in C#.NET.
If you are talking about FORMS, talk about the controls on the form.
So now I am asking, as you said, every form is associated with two tables, How these 2 tables you are displaying on the form? i mean which controls you are using to display the data of the Table ?
This way we can know and figure out what events are available for that control. NOT THE TABLE..
I hope now you understand what I mean to clearify
Regards
|
|
|
|
|
hi.
I am writing a program with c# and sql as database.
i have a MDIform as startup form which one of my form(frmMain) opens with it.
in frmMain i have a combobox which is filled with data from CityTable. it means that I used Value Member and Display Member to fill it.
when I press the button "Add City" on MDIform another form opens and i can add a new city.
the frmMain still is open.
my problem is here how can I update city Combo box in frmMain?
please help me.
i have asked from a few persons and they gave 2 solutions :
1-raise an event
2-open City From using showDialog()
now please tell which one to choose and how?
|
|
|
|
|
As per my knowledge, Do this.
Make the data source(Table containing the Cities) of Combobox, publicly accessible by declaring in the mainForm a static propertly which return the data table of cities.
In the dialog box, where you add new record, access the data table of mainForm and add city in it. It'll automatically shown in combo box because its already bound to that table.
Regards
|
|
|
|
|
thanx for answer
appreciate
|
|
|
|
|
Since C# 3.0 natively supports LINQ in the language wouldn't that make the ADO.NET stuff part of the CLR and BCL?
|
|
|
|
|
Why would LINQ change ADO.NET ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi there,
I have a stored procedure written on a RichTextBox. On the click of a button, this stored procedure should be executed and errors, if any, should be displayed in a messagebox.
Thanks in advance!
|
|
|
|
|
Hi!
You can access the text in the RTB via its Text property (I can't see what else this has to do with the topic).
To execute a SP with a given name you can use classes from the System.Data.* namespace, depending on the RDBMS you want to use, for example the SqlCommand class.
There's a ton of samples for this on MSDN for example, try googling for it if you still have troubles.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks mav,
Currently I am using this option. The problem is that SqlCommand class can handle only one SQL command at time. What I need is to send an entire SP, execute it and after the whole SP is executed in "one go";
1. If successful, a message box saying "Successful Execution" should be displayed; else,
2. Whatever exception has been returned, that needs to be displayed.
|
|
|
|
|
You can't "send an entire SP". A SP is something stored within the DB (hence the name). You _could_ execute an SQL command containing something like "CREATE PROCEDURE ..." to create a SP on-the-fly, but I think that's not a good solution.
If you have several queries you have to execute together, then the SP should be available in the DB, not be created everytime, IMO.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
the Pronblem is i have a table of employeeinfo having attribuyes
EmpID
EmpName
EmpFatherName
GenID
now GenID is a primary key of a separate table having two attributes that is
GenID
Gender
the problem is when the form runs displaying 3 textboxes and one combobox the user must select the entry from gender and click save the values must be stored in the table of sql that is Employeeinfo i saved the first three attributes by the following code
datarow.["EmpID"] = EmpID.text;
but on GenID it gives problem bcoz i want to relate the Gender attribute to the GenID Attribute in the EmployeeInfo table and must be saved in the sql data table
SAS
|
|
|
|
|
Make the combo boxe's Display Member property to Gender and Value Member property to GenID. when assigning the values to employeeinfo use like this
datarow.["EmpID"] = EmpID.text;
.
.
.
datarow.["GenID"] = comboBox.SelectedValue;
Regards
|
|
|
|
|
Hi All,
After constructing a string from a byte[], is it possible to call a static method (I'm pretty sure ther is no memeber method) such as IsPrintable( <string> )? I would expect we would pass in a certainy or threshold value. Or is this one of those 'roll your own' implementations?
Jeff
|
|
|
|
|
Hi!
Of course it is possible to call a static method, but since System.String doesn't offer a static method doing what you want, you'll have to "roll your own".
I guess you could use static methods of System.Char for this (e.g. Char.IsControl() ).
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
hi
I will open the word file with C#2005 but print content file with c#2005
please help meeeeeeeeeee
tanks a lot
|
|
|
|
|
Cannot really be done without the help of the Office Interop Library.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
hi
I will open the word file with C#2005 but print content file with c#2005
please help meeeeeeeeeee
tanks a lot
|
|
|
|
|
|
hi there,
i insert binding navigator and bind it to combobox items like this
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = combobox.Items;
bindingNavigator1.BindingSource = bindingSource;
and its working but it have a problem that when i select any item in combobox then its position dont increase.
to do that i tried to just assign the "selectedindex + 1" of combobox to its position textbox's text in SelectedIndexChanged event
and its shows correct position but its not actual, that mean it just showing, not working
for example
i have 3 items in combobox, and i select 3rd item then it will show position is 3 but the last and next buttons still enabled and first and previous still disabled.
any idea to solve it?
thanks
Becoming Programmer...
|
|
|
|
|
Have you tried the Refresh method?
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
yeah, but it didnt work
Becoming Programmer...
|
|
|
|