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

Self Reference Grid View Re Biding Issue

1 Answer 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ramasamy
Top achievements
Rank 1
Ramasamy asked on 05 Oct 2011, 04:15 AM
Hi,

I am facing problem while rebinding the grid.

In the XAML,

<

 

 

telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding Path=Table, Mode=TwoWay,
UpdateSourceTrigger
=PropertyChanged}" GridLinesVisibility="Both" IsReadOnly="True"

 

 

 

CanUserFreezeColumns="False" RowIndicatorVisibility="Collapsed" CanUserReorderColumns="False"

 

 

 

ShowGroupPanel="False" HorizontalAlignment="Left" SelectionMode="Extended" SelectionUnit="Cell"
BorderThickness
="0">

 

<

 

 

telerik:RadGridView.FilterDescriptors>
<telerik:FilterDescriptor Member="ParentID" Operator="IsEqualTo" Value="0"/>
</telerik:RadGridView.FilterDescriptors>

 

 

 

 

 

 

<

 

 

telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition>
<telerik:GridViewTableDefinition.Relation>
<telerik:TableRelation IsSelfReference="True">
<telerik:TableRelation.FieldNames>
<telerik:FieldDescriptorNamePair ParentFieldDescriptorName="ServiceID" ChildFieldDescriptorName="ParentID"/>
</telerik:TableRelation.FieldNames>
</telerik:TableRelation>
</telerik:GridViewTableDefinition.Relation>
</telerik:GridViewTableDefinition>
</telerik:RadGridView.ChildTableDefinitions>
</telerik:RadGridView>

In the ViewModel,

 

private

 

 

DataTable _table;
public DataTable Table
{
get { return _table; }
set
{
_table =
value;
RaisePropertyChanged(() =>
this.Table);
}
}

 

 

[

 

ImportingConstructor]
public MatrixViewModel(IEventAggregator eventAggregator)
{
this.TabModel = new TabModel { Title = "Matrix" };

if (eventAggregator != null)
eventAggregator.GetEvent<
MatrixReloadEvent>().Subscribe(OnContractCreatedOrLoaded);
}

 

 

 


private
void OnContractCreatedOrLoaded(ContractCreatedOrLoadedEventArgs args)

 

{

 

DataTable dtOutput = new DataTable();
..buliding the datatable and assigning to the Table property
}

 

 

From the other screen I am calling the event "OnContractCreatedOrLoaded" while adding new items. For the first time (add 1 or n number of items) and view the grid screen. It works perfectly (Grid will have only one row - ParentID = 0).

Now add 1 new item ("OnContractCreatedOrLoaded" event will be fired) and see the grid, it binds all the rows in the datatable without filtering or hierarchy (grid is having all the rows instead of showing ParentID = 0)

Any help appreciated.

Thanks,
Ramasamy

1 Answer, 1 is accepted

Sort by
0
Ramasamy
Top achievements
Rank 1
answered on 06 Oct 2011, 08:07 AM
Hi,

I got the solution by removing the FilterDescriptor from the XAML and adding it dynamically in the DataLoading event of the xaml.cs.

if

 

 

(RadGridView1.FilterDescriptors.Count <= 0)
{
FilterDescriptor parentFilter = new FilterDescriptor("ParentID", FilterOperator.IsEqualTo, "0", true);
RadGridView1.FilterDescriptors.Add(parentFilter);
}

Thanks,
Ramasamy

 

Tags
GridView
Asked by
Ramasamy
Top achievements
Rank 1
Answers by
Ramasamy
Top achievements
Rank 1
Share this question
or