Datagrid question

  • Thread starter Thread starter Bob Day
  • Start date Start date
B

Bob Day

Using VS 2003, VB.NET, sql msde...

This is really a question about a winform datagridcontrol (if there is a
better newsgroup for these winform datagridcontrol questions, let me know).

A parent/child relationship exists. When you click the + next to the parent
row, the relationship name "Display Details" appears. You then click that,
and everything previously FILLed to the child DataSet table displays. All
works as expected.

My question are:
1) Is there an event triggered by clicking on "Display Details" so you could
dynamically FILL the child table at that point, instead of having to fill it
prior it "Display Details" being click? If not an event, any other way to
do it?

2) Since the child table in the DataSet is held in memory, should I be
worried about how large it might get? Can it get to large or does Windows
XP/.NET still handle it appropriately regardless of its size? In my case,
the child could get quite large, constantly being added to by the program
automatically (which is the main reason I would like to load it when needed
via #1 above).

Thanks!

Bob Day
 
I'm now performing research on the issue now. I will update you as soon as
possible.

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Based on my research, the event Navigate is fired when the user navigates
to a new table. You can dynamically fill the child table. Please refer to
the following for a sample:

As to the size of the child table, you should control the size. If the size
is very large, it will be timing consuming to display the data.

//==========================================================================
===
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private DataSet ds = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 0);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(292, 266);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.Navigate += new
System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
SqlConnection con = new
SqlConnection("server=Server;uid=sa;pwd=password;database=northwind");
SqlDataAdapter daCust = new SqlDataAdapter("Select * From Customers
Where CustomerID Like 'A%'", con);
SqlDataAdapter daOrders = new SqlDataAdapter("Select * From Orders Where
CustomerID Like 'A%'", con);
ds = new DataSet();
daCust.Fill(ds, "Cust");
daOrders.Fill(ds, "Orders");
//Creates the relationship.
ds.Relations.Add("CustOrd", ds.Tables["Cust"].Columns["CustomerID"],
ds.Tables["Orders"].Columns["CustomerID"]);
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "Cust";
}

private void dataGrid1_Navigate(object sender,
System.Windows.Forms.NavigateEventArgs ne)
{
DataRow row = ds.Tables["Orders"].NewRow();
row["CustomerID"] = "ALFKI";
ds.Tables["Orders"].Rows.Add(row);
}
}
}
//==========================================================================
===

Best regards,

Duke Sun
Microsoft Online Partner Support
<MCSE/MCDBA/MCSD>

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top