Hey gang,
I am near tears at this point. I have an app that runs in the UK and the
US, and have already gone to school on DataTable.Compute and UK date formats
(have to convert to EN-US). Also, the app has an 'online' (vb.net
webservice with typed datasets) and an 'offline' mode (xml files, same
datasets) and I went to school on the fact that some properties set in the
dataset designer do not propogate to the WebReference (Like NullValue).
I have one main data form. It has bound textboxes, combos, and a
usercontrol that formats the date '1/1/1900' to a blank and a blank to
'1/1/1900' since I could not serialize null dates. (arggh)
The problem is this. I usually use a currency manager on my forms. To add
a record I call cm.AddNew. To comit changes I call cm.EndCurrentEdit. Here
is a sample of the initial binding:
Me.dvForm.Table = TaskData.Data.dsTaskData1.tblTask
Me.txtDescr.DataBindings.Add(New System.Windows.Forms.Binding("Text",
Me.dvForm, "Descr"))
Me.cboType.DataSource = TaskData.Data.dsTaskData1
Me.cboType.DisplayMember = "tblType.Name"
Me.cboType.ValueMember = "tblType.ID"
Me.cboType.DataBindings.Add(New
System.Windows.Forms.Binding("SelectedValue", Me.dvForm, "TypeRef"))
. . . . .
cm = Me.BindingContext(Me.dvForm)
I need to set some values when I call AddNew. Since they are calculated, I
don't want to update the autogenerated (WSDL) class, I want to calculate
them on the form itself. I have tried setting the TextBox.Text property to
the value, and I have tried setting the CType(cm.current,
DataRowView)("TypeRef") and I have tried using AddNew on the DataView
(dvForm). Which is the right way to go, cm.AddNew or dvForm.AddNew? If
this works right, when I do an AddNew, will my comboboxes be blank, or set
to the first value in the list? I prefer them to be blank because it makes
more sense to the user.
I used to have an issue where the cm would not go to the new row when, for
instance, a checkbox was bound to a field and the field value was
DBNull.Value. I have been up for a long time, and I am getting stupid-er,
and can't get things working. I have eliminated the bindings to be sure
none are breaking the move to the new row, but can't track it down.
Final note: Some of the comboboxes are related to each other in a
heirarchical way. In dvForm, there are 4 levels of locations. In the
DataSet, there are 4 tables related to each other. My binding here seem to
be working right.
Thanks for ANY help!
Kevin
Ken Tucker [MVP] - 15 Jul 2004 00:57 GMT
Hi,
Did you try setting the default values for the datacolumns?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdatadatacolumnclassdefaultvaluetopic.asp
Ken
--------------------
> Hey gang,
>
[quoted text clipped - 61 lines]
>
> Kevin
a - 15 Jul 2004 01:27 GMT
I do have some default values set for this table. I have a sub
New(intSelectedID) that first calls me.New(). I was putting my databinding
in that sub, then setting the cm = me.bindingcontext . . in the Form load
event. When I put it all in the Load event, it works.
Don't know what that's about. The DataSet is a Shared member of my Data
Access class.
Kevin
> Hi,
>
> Did you try setting the default values for the datacolumns?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemdatadatacolumnclassdefaultvaluetopic.asp
> Ken
> --------------------
[quoted text clipped - 63 lines]
> >
> > Kevin
Rhett Gong [MSFT] - 15 Jul 2004 10:04 GMT
Hi Kevin,
From the nature of this issue, seems we need some time researching on it. We will
update you later when we get an answer. Thanks for your patience.
Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
a - 15 Jul 2004 16:09 GMT
Rhett,
Please let me know if I can provide any more code to help.
I tried binding to the dataset itself (which is a Shared member of another
Class), and it works if I set the bindings in LOAD, but not in NEW. If I
want to programmatically add a value, is it best to set the text property of
my control, then set the focus to that control to trigger validation? Or, is
there a way to get the DataRowView from the CurrencyManager and set it like
that?
My question is because when I first load the form with a call to AddNew,
then set a value:
cm.AddNew
Dim drv As DataRowView
drv = CType(cm.Current, DataRowView)
'Set ProjectRef
drv.Item("ProjectRef") = intProjectRef
'Set TaskNum
drv.Item("Num") = GetNextTaskNum()
It works fine. After saving that record and calling AddNew again, my txtNum
TextBox does not show the value from GetNextTaskNum as it should.
I can't find the pattern.
Kevin
> Hi Kevin,
> From the nature of this issue, seems we need some time researching on it. We will
[quoted text clipped - 6 lines]
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Please reply to newsgroups only. Thanks.
"Ying-Shen Yu[MSFT]" - 16 Jul 2004 04:53 GMT
Hi Kevin,
To my understanding now, your question is how to add a new row like the
behavior of BindingManagerBase.AddNew, in addition you need set several
items in this process.
I think the following way may be helpful to you:
You may derive to create your own DataView , say MyDataView, then override
the DataView.AddNew method and set items in this method and return the new
row , it's just like
<code>
public override DataRowView AddNew()
{
DataRowView drv = base.AddNew ();
//set Items in DataRowView;
return drv;
}
</code>
Then bind the textboxes to MyDataView , when you need add a new row , we
may just get the CurrencyManager of the view and call
CurrencyManager.AddNew method,
<code>
CurrencyManager cm = (CurrencyManager)BindingContext[view];
cm.AddNew();
</code>
CurrencyManager will internally use the AddNew method on the view, so the
item will be filled automcatically.
Does it resolve your problem?
If not, please let me know more detail about your problem, I'll try to see
if I can think of a solution for it.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.