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

Winforms Q2 2009 Refresh Hierarchical Grid

1 Answer 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George Kousis
Top achievements
Rank 1
George Kousis asked on 19 Jul 2010, 02:11 PM
Hi,

I have a GridView control that I bind to a dataset that contains two tables.  I then create the relationship and display the hierarchy fine.  I want to control the way that new rows are added in my grid so the AllowAddNewRow for both master and child tables is set to false.  I have a custom form that creates new rows.  To simulate this, I just have a command column that inserts some hardcoded values into the grid.
The problem is that I cannot get the grid to refresh with the newly added records in the child table.  When I click the "Add" command column, a vertical scroll bar appears in the child table but I cannot see the rows.  Below is the sample code that I have.  Any ideas will be greatly appreciated.  Thanks.

Private

 

Sub frmCustomProperties_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

 

 

 


Dim
adpProperties As New SqlDataAdapter()

 

' ... here I populate the database with two tables named cntCustomProperties and PropertyValues

 

adpProperties.Fill(dsProperties)

 

 

 

' set the master

 

 

grdProperties.DataSource = dsProperties.Tables(

"cntCustomProperties")

 

grdProperties.MasterGridViewTemplate.AllowAddNewRow =

 

False

 

 

grdProperties.MasterGridViewTemplate.AllowDeleteRow =

False

 

 

grdProperties.MasterGridViewTemplate.AllowEditRow =

False

 

 

 

' template for values

 

 

 

Dim ValuesTemplate As Telerik.WinControls.UI.GridViewTemplate = New Telerik.WinControls.UI.GridViewTemplate

 

ValuesTemplate.DataSource = dsProperties.Tables(

 

"PropertyValues")

 

ValuesTemplate.AllowAddNewRow =

 

False

 

 

ValuesTemplate.AllowDeleteRow =

False

 

 

ValuesTemplate.AllowEditRow =

False

 

 

grdProperties.MasterGridViewTemplate.ChildGridViewTemplates.Add(ValuesTemplate)

 

' configure relation between two tables

 

 

 

Dim relation As Telerik.WinControls.UI.GridViewRelation = New Telerik.WinControls.UI.GridViewRelation(grdProperties.MasterGridViewTemplate)

 

relation.ChildTemplate = ValuesTemplate

relation.RelationName =

 

"p2v"

 

 

relation.ParentColumnNames.Add(

"PropertyId")

 

relation.ChildColumnNames.Add(

 

"PropertyId")

 

grdProperties.Relations.Add(relation)

 

 

' now configure the two templates

 

 

grdProperties.MasterGridViewTemplate.Columns(

"PropertyId").IsVisible = False

 

 

grdProperties.MasterGridViewTemplate.Columns(

"PropertyName").BestFit()

 

 

 

Dim cmdColumnAdd As New GridViewCommandColumn()

 

cmdColumnAdd.UniqueName =

 

"cmdColumnAdd"

 

 

cmdColumnAdd.UseDefaultText =

True

 

 

cmdColumnAdd.DefaultText =

"Add"

 

 

cmdColumnAdd.FieldName =

"PropertyId"

 

 

cmdColumnAdd.HeaderText =

"Add"

 

 

cmdColumnAdd.BestFit()

grdProperties.MasterGridViewTemplate.Columns.Add(cmdColumnAdd)

ValuesTemplate.Columns(

"PropertyId").IsVisible = False

 

 

ValuesTemplate.Columns(

"PropertyValueId").IsVisible = False

 

 

ValuesTemplate.Columns(

"CompanyCode").IsVisible = False

 

 

ValuesTemplate.Columns(

"EffectiveFrom").BestFit()

 

ValuesTemplate.Columns(

 

"Value").BestFit()

 

 

 

Dim cmdColumnEdit As New GridViewCommandColumn

 

cmdColumnEdit.UniqueName =

 

"cmdColumnEdit"

 

 

cmdColumnEdit.UseDefaultText =

True

 

 

cmdColumnEdit.DefaultText =

"Edit"

 

 

cmdColumnEdit.FieldName =

"PropertyValueId"

 

 

cmdColumnEdit.HeaderText =

"Edit"

 

 

cmdColumnEdit.BestFit()

ValuesTemplate.Columns.Add(cmdColumnEdit)

 

 

AddHandler grdProperties.CommandCellClick, AddressOf grdProperties_CommandCellClick

 

 

 

 

 

End Sub


 

Sub

 

grdProperties_CommandCellClick(ByVal sender As Object, ByVal e As EventArgs)

 

 

 

Dim cmdCell As GridCommandCellElement

 

cmdCell =

 

TryCast(sender, GridCommandCellElement)

 

 

 

Dim tName As String = CType(cmdCell.ViewTemplate.DataSource, DataTable).TableName

 

 

 

If tName = "cntCustomProperties" Then

 

 

 

 

 

   AddCustomProperty(cmdCell.Value)

 

 

ElseIf tName = "PropertyValues" Then

 

 

 

 

 

   '-- code for the edit here

 

End If

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End Sub

 

 

 

 

 

 

 



Private
Sub AddCustomProperty(ByVal pid As Integer)

 

 

 


Dim
nr As DataRow = dsProperties.Tables("PropertyValues").NewRow

 

nr.BeginEdit()

nr(

 

"propertyid") = pid

 

nr(

 

"companycode") = "10"
nr(
"effectivefrom") = "1900/1/1"

 

 

 

 

 

nr(

 

"value") = "some new value here"

 

 

 

 

 

nr.EndEdit()

dsProperties.Tables(

 

"PropertyValues").Rows.Add(nr)

 

dsProperties.Tables(

 

"PropertyValues").AcceptChanges()

 

' I have tried many combinations but none seems to work.
grdProperties.GridElement.Update(GridUINotifyAction.AddRow)

 

 

'grdProperties.MasterGridViewTemplate.Update(GridUINotifyAction.BatchDataChanged)

 

 

 

 

 

 

 

'grdProperties.MasterGridViewTemplate.ChildGridViewTemplates(0).Update(GridUINotifyAction.BatchDataChanged))

 

 

 

 

 

 

 

 

End Sub

 

 

 

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 20 Jul 2010, 06:11 PM
Hi George Kousis,

I confirm that this issue existed in previous versions of RadGridView. However, it is addressed in our latest release - Q2 2010. I recommend that you try this version. It contains many new features and addresses a lot of issues. If the issue continues to appear, please send me your application and I will investigate the case in detail.

I am looking forward to your reply.

Best wishes,
Jack
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
George Kousis
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or