I have a grid and its DataSource is assigned on the constructor of MainWindow.xaml.cs
A delegate is fired on later in the program and in there I want to rebind the Grid so I have tried setting it to null and then to the new model but the InitializeRecord is not fired when the DataSource is assigned.
Can you help please?
Hello,
I am just checking if you require any further assistance on the matter.
The event ‘InitializeRecord’ seems to fire every time when you change the data in the XamDataGrid. The code for the XamDataGrid that you are looking for looks like :
private void xamDataGrid1_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
{
if (e.Record.HasChildren != false)
bool flag = false;
foreach (Record r2 in e.Record.ViewableChildRecords)
//Do some logic
if (flag)
break;
}
e.Record.Visibility = Visibility.Collapsed;
For more information about how to use our XamDataGrid you can look through our online documentation :
http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=xamDataGrid.html
Ok, I see it working now however what I have is a hierarchy grid and I'm trying to port some Winforms code over to WPF. In Winforms I have InitializeRow which I believe fires once for each parent row. I have access to the row and the child rows. I want this in WPF as InitliazeRecord seems to fire a lot eg/on databinding and heirarchy expansion. Is there a similar event so when the databinding occurs a similar event fires once that gives me the access to row and child rows.
I have something similar to the below:
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using Infragistics.Windows.DataPresenter;using Infragistics.Windows.Controls;using System.Windows.Automation;using System.Collections.ObjectModel;
namespace datagridfieldsettings{ ///
/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public DataSet dsDataSet = new DataSet();
public MainWindow() { InitializeComponent();
DataTable dtCustomer = new DataTable(); dtCustomer.Columns.Add(new DataColumn("Id")); dtCustomer.Columns.Add(new DataColumn("Name"));
DataTable dtOrders = new DataTable(); dtOrders.Columns.Add(new DataColumn("Id")); dtOrders.Columns.Add(new DataColumn("CustomerID")); dtOrders.Columns.Add(new DataColumn("OrderTotal"));
dsDataSet.Tables.Add(dtCustomer); dsDataSet.Tables.Add(dtOrders);
for (int i = 0; i < 5;i++ ) { DataRow row = dtCustomer.NewRow(); row["Id"] = i; row["Name"] = "John Smith"; dtCustomer.Rows.Add(row);
DataRow custRow = dtOrders.NewRow(); custRow["Id"] = i; custRow["CustomerID"] = i; custRow["OrderTotal"] = i*10; dtOrders.Rows.Add(custRow);
dsDataSet.Relations.Add(new DataRelation("link", dsDataSet.Tables[0].Columns[0], dsDataSet.Tables[1].Columns[1]));
this.xamDataGrid1.DataSource = dsDataSet.Tables[0].DefaultView;
private void button1_Click(object sender, RoutedEventArgs e) { this.xamDataGrid1.DataSource = null; this.xamDataGrid1.DataSource = dsDataSet.Tables[0].DefaultView; }
private void xamDataGrid1_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e) { string hit = "hi"; } }}
In Winforms I can do something like this:
private void ultraGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { if (e.Row.ChildBands != null) { bool found = false;
foreach (Infragistics.Win.UltraWinGrid.UltraGridRow r2 in e.Row.ChildBands[0].Rows) { //Do some logic if (found) break;
} e.Row.Hidden = !found; } }
I have been looking into your post and I have tested the described behavior. It seems that the event fires. Would you please modify the attach sample application(datagridchangdatasource.zip) in order to reproduce exactly your scenario ?
Looking forward to hearing from you.