This is a migrated thread and some comments may be shown as answers.

Hierarchical Data Binding not working

3 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Toxic
Top achievements
Rank 1
Toxic asked on 11 Sep 2012, 04:07 PM
Hi there,

I must be missing something but I cannot get my data elements to bind.

My code is quite straightforward.

I have two data readers :

Dim myCommand1 As New System.Data.SqlClient.SqlCommand("prcAccess_GetHeaderTransactionList", myConnection1)
myCommand1.CommandType = System.Data.CommandType.StoredProcedure
myConnection1.Open()
Dim myreader1 As SqlDataReader = myCommand1.ExecuteReader()

Dim myCommand3 As New System.Data.SqlClient.SqlCommand("prcAccess_GetDetailTransactionListByAccountNo", myConnection3)
myCommand3.CommandType = System.Data.CommandType.StoredProcedure
myConnection3.Open()
Dim myreader3 As SqlDataReader = myCommand3.ExecuteReader()


The first has a field "ST_ORDER_NUMBER" the second has one called "OH_ORDER_NUMBER"

I use the following code to bind and relate :

RadGridView3.DataSource = myreader1
Dim template As New GridViewTemplate()
template.DataSource = myreader3
RadGridView3.MasterTemplate.Templates.Add(template)
Dim relation As New GridViewRelation(RadGridView3.MasterTemplate)
relation.ChildTemplate = template
relation.RelationName = "OrderNumber"
relation.ParentColumnNames.Add("ST_ORDER_NUMBER")
relation.ChildColumnNames.Add("OH_ORDER_NUMBER")
RadGridView3.Relations.Add(relation)


Everything looks ok. But the the detail items are not displaying.

What am I missing?

Cheers

Tox

3 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 14 Sep 2012, 12:16 PM
Hi Tox,

Thank you for contacting Telerik Support.

To extract values from a data source using a SqlDataReader, use the GridViewTemplate LoadFrom() method. For example:
Dim myreader As SqlDataReader = myCommand.ExecuteReader()
Dim template As New GridViewTemplate()
template.LoadFrom(myreader)

I would suggest that you to find more information at this documentation article: http://www.telerik.com/help/winforms/gridview-populating-with-data-binding-to-datareader.html.

I hope this information helps. If you have further questions, feel free to write back.

Kind regards,
Anton
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Toxic
Top achievements
Rank 1
answered on 17 Sep 2012, 08:47 AM
Thanks, that works now.

But I am now finding a different problem.

I am creating the columns thus :
    Dim newcolumn_subtotal As New GridViewTextBoxColumn("subtotal")
            newcolumn_subtotal.HeaderText = "Sub Total"
            newcolumn_subtotal.FieldName = "OD_NETT"
            newcolumn_subtotal.IsVisible = True
            newcolumn_subtotal.FormatString = "{0:C2}"
            newcolumn_subtotal.TextAlignment = ContentAlignment.MiddleRight
            template.Columns.Add(newcolumn_subtotal)

Where template is my sub view in the structure. But for some reason, although setting the formatstring in the main gridview makes the currency appear correctly, when doing so on the fly in the above code with the FormatString statement. The data format does not change.
I cannot see this is a data problem since I use the same data succesfully formatted in a non Hierarchical structure with the formatstring applied......  can this only be applied at design time?

Cheers

Tox
0
Anton
Telerik team
answered on 18 Sep 2012, 01:08 PM
Hi Tox,

Thank you for writing back.

I tried to reproduce the problem locally but to no avail – everything is working as expected on my side. There is sample demo project attached which I have used in my tests. Could you please take a look at it and modify it on a way to replicate the undesired behavior. This will allow me to investigate it and provide you with further support.

Thank you in advance for your collaboration. I am looking forward to your reply.

All the best,
Anton
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Toxic
Top achievements
Rank 1
Answers by
Anton
Telerik team
Toxic
Top achievements
Rank 1
Share this question
or