
DataView filter not working in MDI child forms with reference to MDI parent DataSet
For some reason, DataView filters within an MDI child form do not seem to work when applied against a referenced DataSet passed to child forms by an MDI container.
Code fragments are : (The last line is the DataView filter that does not work in child forms)
A) wbmain.cs (MDI Parent)
private WhiteBoard.Windows.Client.WebServices.WhiteBoardDS whiteBoardDS1;
private void wbmain_Load(object sender, System.EventArgs e)
{
setCurrentForm(new frmMain(whiteBoardDS1)); // DS reference passed to child form
Quote:
}
private void setCurrentForm(Form f)
{
if (f==null) return;
if (f==currForm) return;
f.TopLevel = false;
f.MdiParent = this;
pnlMain.Controls.AddRange(new System.Windows.Forms.Control[] { f });
f.Dock = DockStyle.Fill;
f.BringToFront();
f.Show();
if (currForm != null)
{
currForm.Close();
pnlMain.Controls.Remove(currForm);
}
currForm = f;
Quote:
}
private void GetWhiteBoardDS() // Fired on menu and toolbar events
{
Service1 s1 = new WhiteBoard.Windows.Client.WebServices.Service1();
try
{
this.Cursor = Cursors.WaitCursor;
whiteBoardDS1.Merge(s1.GetWhiteBoardDS());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show("Data will be loaded from local cache");
whiteBoardDS1.ReadXml("c:\\data\\whiteboard.xml");
}
finally
{
this.Cursor = Cursors.Default;
frmBase activeChild = (frmBase) currForm;
if (activeChild != null)
{
activeChild.AfterWhiteboardDSFill();
}
}
Quote:
}
B) frmBase.cs (base form for all MDI child forms)
public class frmBase : System.Windows.Forms.Form
{
protected WhiteBoard.Windows.Client.WebServices.WhiteBoardDS whiteBoardDS1;
protected System.Data.DataView vCompany;
private System.ComponentModel.Container components = null;
public frmBase()
{
InitializeComponent();
}
// [CODE SNIPPED FOR BREVITY]
public virtual void SaveWhiteBoardDS(){}
public virtual void AfterWhiteboardDSFill(){}
Quote:
}
C) frmMain.cs (primary child form within MDI container -- inherited from frmBase)
public class frmMain : WhiteBoard.Windows.Client.frmBase
{
public override void AfterWhiteboardDSFill()
{
if (ugCompany.Rows.Count > 0)
{
ugCompany.Rows[0].Activate();
}
BuildValueLists();
}
public frmMain(WhiteBoardDS ds)
{
InitializeComponent();
whiteBoardDS1 = ds; // Reference to parent DS cached in base form
}
private void InitializeComponent()
{
this.ugCompany.DataSource = this.vCompany; // DataView bound to grid
}
private void SetCompanyTypeFilter() // DS previously filled.
{
string s1 = "Type = ''";
if (cbDeveloper.Checked && cbDesignCenter.Checked)
s1 = "Type = '1' OR Type = '2'";
else
if (cbDeveloper.Checked)
s1 = "Type = '1'";
else
if (cbDesignCenter.Checked)
s1 = "Type = '2'";
vCompany.Table = whiteBoardDS1.Tables["wbtCompany"];
vCompany.RowFilter = s1; // THIS FILTER DOES NOT WORK IN CHILD!!!
}
Quote:
}