Home All Groups Group Topic Archive Search About

Datagrid binding problem

Author
20 Apr 2006 4:59 PM
no
Hi all,

I have a dataset that contain 2 tables and a relationship between them
(master detail).
I bind this dataset to a form that include some textboxes that bind to the
parent record, and a datagrid that is binded to the detailed records.

Here is the code:

Code:
Private Sub FillHeader(ByRef dsDataSet As DataSet)
  Try
    txtKey.DataBindings.Add(New Binding("text", dsDataSet , "header.key"))
    txtNo.DataBindings.Add(New Binding("text", dsDataSet , "header.no"))
  Catch ex As Exception
    HandleExceptions(ex)
  End Try
End Sub

Code:
Private Sub FillLines(ByRef dsDataSet As DataSet)
  Try
    dsDataSet.Tables("lines").Columns("key").ColumnMapping =
MappingType.Hidden
    dsDataSet.Tables("lines").Columns("product_id").ColumnName = "Product
Id"
    dsDataSet.Tables("lines").Columns("quantity").ColumnName = "Quantity"
    dgLines.SetDataBinding(dsDataSet.Tables!lines, "HeaderLines")
  Catch ex As Exception
    HandleExceptions(ex)
  End Try
End Sub

The sub I use to navigate is (For example I put only the next command):

Code:
Sub cmdNext() Implements ICommandNext.cmdNext
  Try
    bdRecordNavigator = BindingContext(dsHeader, "header")
    bdRecordNavigator.Position += 1
  Catch ex As Exception
    HandleExceptions(ex)
  End Try
End Sub

My problem happens when I navigate between the master records. The textboxes
show the correct values, but there is no change in the datagrid. What do I
miss here, that this sub will handle the datagrid as well?

Thanks

Author
20 Apr 2006 4:52 PM
Ken Tucker [MVP]
Hi,

          You need to use datagrid.setdatabinding to get the child grid to
only display the filtered records.

http://www.vb-tips.com/default.aspx?ID=a1a84750-08df-49b4-8657-7bc3068aca2c

http://www.vb-tips.com/default.aspx?ID=3eafa9ea-a906-45ff-aece-e8335682ad3a

Ken
-----------------

Show quoteHide quote
"no" wrote:

> Hi all,
>
> I have a dataset that contain 2 tables and a relationship between them
> (master detail).
> I bind this dataset to a form that include some textboxes that bind to the
> parent record, and a datagrid that is binded to the detailed records.
>
> Here is the code:
>
> Code:
> Private Sub FillHeader(ByRef dsDataSet As DataSet)
>   Try
>     txtKey.DataBindings.Add(New Binding("text", dsDataSet , "header.key"))
>     txtNo.DataBindings.Add(New Binding("text", dsDataSet , "header.no"))
>   Catch ex As Exception
>     HandleExceptions(ex)
>   End Try
> End Sub
>
> Code:
> Private Sub FillLines(ByRef dsDataSet As DataSet)
>   Try
>     dsDataSet.Tables("lines").Columns("key").ColumnMapping =
> MappingType.Hidden
>     dsDataSet.Tables("lines").Columns("product_id").ColumnName = "Product
> Id"
>     dsDataSet.Tables("lines").Columns("quantity").ColumnName = "Quantity"
>     dgLines.SetDataBinding(dsDataSet.Tables!lines, "HeaderLines")
>   Catch ex As Exception
>     HandleExceptions(ex)
>   End Try
> End Sub
>
> The sub I use to navigate is (For example I put only the next command):
>
> Code:
> Sub cmdNext() Implements ICommandNext.cmdNext
>   Try
>     bdRecordNavigator = BindingContext(dsHeader, "header")
>     bdRecordNavigator.Position += 1
>   Catch ex As Exception
>     HandleExceptions(ex)
>   End Try
> End Sub
>
> My problem happens when I navigate between the master records. The textboxes
> show the correct values, but there is no change in the datagrid. What do I
> miss here, that this sub will handle the datagrid as well?
>
> Thanks
>
>
>
Author
20 Apr 2006 8:31 PM
Ohad Weiss
Ken Tucker,
Thanks for your reply
The tips you supplyed heled me a lot.

All I had to do was to add a line before the catch statement that solved the
whole problem:
dgItems.SetDataBinding(dsPOHeader, "purchase_order_header.POHeaderLines")



Thanks again

Ohad



Show quoteHide quote
"Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message
news:B5C41781-8D8F-487C-9F7C-D9B3817FD490@microsoft.com...
> Hi,
>
>          You need to use datagrid.setdatabinding to get the child grid to
> only display the filtered records.
>
> http://www.vb-tips.com/default.aspx?ID=a1a84750-08df-49b4-8657-7bc3068aca2c
>
> http://www.vb-tips.com/default.aspx?ID=3eafa9ea-a906-45ff-aece-e8335682ad3a
>
> Ken
> -----------------
>
> "no" wrote:
>
>> Hi all,
>>
>> I have a dataset that contain 2 tables and a relationship between them
>> (master detail).
>> I bind this dataset to a form that include some textboxes that bind to
>> the
>> parent record, and a datagrid that is binded to the detailed records.
>>
>> Here is the code:
>>
>> Code:
>> Private Sub FillHeader(ByRef dsDataSet As DataSet)
>>   Try
>>     txtKey.DataBindings.Add(New Binding("text", dsDataSet ,
>> "header.key"))
>>     txtNo.DataBindings.Add(New Binding("text", dsDataSet , "header.no"))
>>   Catch ex As Exception
>>     HandleExceptions(ex)
>>   End Try
>> End Sub
>>
>> Code:
>> Private Sub FillLines(ByRef dsDataSet As DataSet)
>>   Try
>>     dsDataSet.Tables("lines").Columns("key").ColumnMapping =
>> MappingType.Hidden
>>     dsDataSet.Tables("lines").Columns("product_id").ColumnName = "Product
>> Id"
>>     dsDataSet.Tables("lines").Columns("quantity").ColumnName = "Quantity"
>>     dgLines.SetDataBinding(dsDataSet.Tables!lines, "HeaderLines")
>>   Catch ex As Exception
>>     HandleExceptions(ex)
>>   End Try
>> End Sub
>>
>> The sub I use to navigate is (For example I put only the next command):
>>
>> Code:
>> Sub cmdNext() Implements ICommandNext.cmdNext
>>   Try
>>     bdRecordNavigator = BindingContext(dsHeader, "header")
>>     bdRecordNavigator.Position += 1
>>   Catch ex As Exception
>>     HandleExceptions(ex)
>>   End Try
>> End Sub
>>
>> My problem happens when I navigate between the master records. The
>> textboxes
>> show the correct values, but there is no change in the datagrid. What do
>> I
>> miss here, that this sub will handle the datagrid as well?
>>
>> Thanks
>>
>>
>>
Author
20 Apr 2006 8:54 PM
Ohad Weiss
Ken Tucker,
Thanks for your reply
The tips you supplyed heled me a lot.

All I had to do was to add a line before the catch statement that solved the
whole problem:
dgLines.SetDataBinding(dsDataSet, "header.HeaderLines")



Thanks again

Ohad

Show quoteHide quote
"Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message
news:B5C41781-8D8F-487C-9F7C-D9B3817FD490@microsoft.com...
> Hi,
>
>          You need to use datagrid.setdatabinding to get the child grid to
> only display the filtered records.
>
> http://www.vb-tips.com/default.aspx?ID=a1a84750-08df-49b4-8657-7bc3068aca2c
>
> http://www.vb-tips.com/default.aspx?ID=3eafa9ea-a906-45ff-aece-e8335682ad3a
>
> Ken
> -----------------
>
> "no" wrote:
>
>> Hi all,
>>
>> I have a dataset that contain 2 tables and a relationship between them
>> (master detail).
>> I bind this dataset to a form that include some textboxes that bind to
>> the
>> parent record, and a datagrid that is binded to the detailed records.
>>
>> Here is the code:
>>
>> Code:
>> Private Sub FillHeader(ByRef dsDataSet As DataSet)
>>   Try
>>     txtKey.DataBindings.Add(New Binding("text", dsDataSet ,
>> "header.key"))
>>     txtNo.DataBindings.Add(New Binding("text", dsDataSet , "header.no"))
>>   Catch ex As Exception
>>     HandleExceptions(ex)
>>   End Try
>> End Sub
>>
>> Code:
>> Private Sub FillLines(ByRef dsDataSet As DataSet)
>>   Try
>>     dsDataSet.Tables("lines").Columns("key").ColumnMapping =
>> MappingType.Hidden
>>     dsDataSet.Tables("lines").Columns("product_id").ColumnName = "Product
>> Id"
>>     dsDataSet.Tables("lines").Columns("quantity").ColumnName = "Quantity"
>>     dgLines.SetDataBinding(dsDataSet.Tables!lines, "HeaderLines")
>>   Catch ex As Exception
>>     HandleExceptions(ex)
>>   End Try
>> End Sub
>>
>> The sub I use to navigate is (For example I put only the next command):
>>
>> Code:
>> Sub cmdNext() Implements ICommandNext.cmdNext
>>   Try
>>     bdRecordNavigator = BindingContext(dsHeader, "header")
>>     bdRecordNavigator.Position += 1
>>   Catch ex As Exception
>>     HandleExceptions(ex)
>>   End Try
>> End Sub
>>
>> My problem happens when I navigate between the master records. The
>> textboxes
>> show the correct values, but there is no change in the datagrid. What do
>> I
>> miss here, that this sub will handle the datagrid as well?
>>
>> Thanks
>>
>>
>>