Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Can't initialize readonly fields on child-form in master DGV/child 'detail' edit form
 

Can't initialize readonly fields on child-form in master DGV/child 'detail' edit form

I'm using VS 2008, with an Access database(company requirement)

I have an application where I haveform1 that uses a datagridview to display user id's/names. All fields are read-only, as I want to use form2 as the update/insert form. I am using a bindingsource/bindingnavigator on form1. I have a 'doubleclick' event on form1 to select which row to edit. Form2 opens ok... can save the changes... but I have two fields/db-columns that are not user update-able (date-added & date-updated). I'm trying to update either/both fields when the form2 'save' button is clicked. Also, the save button closes the form. If the user closes usingthe 'X' controlbox, then any changes are ignored.

Also, when I addnew, I want to initalize the dateadded and the dateupdated fields.

The bindingsource is to a 'dataset'.

Can anyone help with this? I've been banging my head for several days.

The code base I'm using is from the 'codeproject' subject titled: "DataGridView with Detail Edit Form - VS 2005'.

Thanks.
BigDaddyCoder  Thursday, August 13, 2009 11:37 PM
Hi BigDaddyCoder,

I have read your post and here is my suggestion to your question.
Do you pass the DateTime column to the form2?
If you pass the DateTime column to form2, you can make that column uneditable, when user finish edit and click save button, you can set that DateTime field with "System.DateTime.Now.ToString()" for example. Then pass that row back to the form1 and change the value.

For the newly added row, you can also set "System.DateTime.Now.ToString()" for the datetime column when form2 is loaded. So the initial value is now.

If I misunderstood you or if you have anything unclear with my post, please feel free to tell me.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, August 17, 2009 3:22 AM
What's not clear from your post is what's the relationship between Form1 and Form2 has it pertains to the DataSet that ou're editing. Are you passing the DataSet to Form2? Or are you passing the DataRow from the DataSet to Form2?

>>I'm trying to update either/both fields when the form2 'save' button is clicked. Also, the save button closes the form. If the user closes usingthe 'X' controlbox, then any changes are ignored. <<

If you are asking how toget the changes saved when the user closes the the Form with the "X", then take a look at the FormClosing event. There you can determine if the data has changed and needs saving and can prompt the user with a dialog prior to the Form closing.

~~Bonnie Berent [C# MVP]
BonnieB  Monday, August 17, 2009 4:46 AM
We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post editor window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, August 20, 2009 7:29 AM
Kira and Bonnie,

My problem was getting access to the fields in the datarow. I was finally able to make it work, but it seems counter-intuitive... I had to create my own 'update-query', as the generated one wouldn't work. The generated 'insert' worked, but not the update.

What I was really asking was: In the dataset designer one is supposed to be able to put a 'default value'. I've tried several variations of NOW(), DateTime(), TO_DATE()... None of them work at runtime.

Is there a list 'somewhere' of what the values can be in this property field? It always has <DBNULL>... ok, but what are the other valid 'things' that can beassinged to the default value property?
BigDaddyCoder  Monday, September 14, 2009 9:35 PM

You can use google to search for other answers

Custom Search

More Threads

• dynamic datagrid with differant colums and data for every query
• modifying the data in Strongly typed dataset before updating to the database
• Visual Studio 2008 IDE How to remove a data source from a form or project?
• Catching DataTable change events in databound form
• Very noob Question about DataGridView toolbox function
• Refreshing in VS 2005 !!!
• DataBind to specific rows
• Help! Design Time Databinding With DataSets in VS2005
• Collapsible and expansible GridView
• How To (VB): Binding subset of records from a code table to a combo box(s)