.NET Framework Bookmark and Share   
 index > .NET Base Class Library > ques
 

ques

how to declear datagrid?
narendra pratap
Here's some help: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/ef62be78-e33b-4499-9b1a-d8b96600a10c.
MCP
webJose
What type of application are you working on? WinForms? Web app? .NET 1.1?
Here's a winform that displays a DataTable passed in its' constructor.

public partial class DataTableForm : Form

{

#region Do not modify code in this region

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing && (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.dataGridView1 = new System.Windows.Forms.DataGridView();

((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();

this.SuspendLayout();

//

// dataGridView1

//

this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;

this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;

this.dataGridView1.Location = new System.Drawing.Point(0, 0);

this.dataGridView1.Name = "dataGridView1";

this.dataGridView1.Size = new System.Drawing.Size(292, 266);

this.dataGridView1.TabIndex = 0;

//

this.dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.AliceBlue;

this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Aqua;

this.dataGridView1.EnableHeadersVisualStyles = false;

//

this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);

//

// DataTableForm

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.Add(this.dataGridView1);

this.Name = "DataTableForm";

this.Text = "DataTableForm";

this.Load += new System.EventHandler(this.DataTableForm_Load);

((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.DataGridView dataGridView1;

#endregion

DataTable dataTable;

BindingSource bindingSource;

public DataTableForm()

{

InitializeComponent();

this.Load+=new EventHandler(DataTableForm_Load);

this.dataTable = new DataTable();

}

public DataTableForm(DataTable table)

: this()

{

table.Locale = System.Globalization.CultureInfo.InvariantCulture;

this.dataTable = table;

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

// do something here !!!

}

private void DataTableForm_Load(object sender, EventArgs e)

{

this.bindingSource = new BindingSource();

this.bindingSource.DataSource = this.dataTable;

this.dataGridView1.DataSource = this.bindingSource;

dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

this.dataGridView1.Invalidate();

return;

}

}



Rudedog =8^D


Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2

You can use google to search for other answers

Custom Search

More Threads

• Serialport portName problem
• Target Type of Binary
• Convert Int32 to Unknown Enum
• Print word document to specific try
• Timer
• screen saver forgets .Net user settings
• Find method in Generic List. c# syntax in VB.NET
• loading external assembly with assembly name's code base set
• How to open files in C#?
• What is .net?