all groups > dotnet windows forms databinding > july 2004 >
You're in the

dotnet windows forms databinding

group:

DataView binding


DataView binding a
7/14/2004 1:06:25 PM
dotnet windows forms databinding: 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


Re: DataView binding Ken Tucker [MVP]
7/14/2004 7:57:29 PM
Hi,

Did you try setting the default values for the datacolumns?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassdefaultvaluetopic.asp


Ken
--------------------
[quoted text, click to view]

Re: DataView binding a
7/14/2004 8:27:35 PM
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


[quoted text, click to view]

RE: DataView binding v-raygon NO[at]SPAM online.microsoft.com
7/15/2004 9:04:55 AM
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.
Re: DataView binding a
7/15/2004 11:09:47 AM
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


[quoted text, click to view]

Re: DataView binding v-yiy NO[at]SPAM online.microsoft.com (
7/16/2004 3:53:53 AM
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.
AddThis Social Bookmark Button