Click here to Skip to main content
15,918,889 members

Comments by gaurigan (Top 2 by date)

gaurigan 26-Dec-15 7:56am View    
public DataTable _dtDataSource = null;
static int count = 0;
public gridviewtable()
{
InitializeComponent(); BindData();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}
private void CreateDataSource()
{
this._dtDataSource = new DataTable("dtDataSource");

DataColumn dcName = new DataColumn("Name");
DataColumn dcCity = new DataColumn("City");
DataColumn dcCountry = new DataColumn("Country");

this._dtDataSource.Columns.Add(dcName);
this._dtDataSource.Columns.Add(dcCity);
this._dtDataSource.Columns.Add(dcCountry);

DataRow dr = this._dtDataSource.NewRow();

dr["Name"] = "VIVEK";
dr["City"] = "NEW DELHI";
dr["Country"] = "INDIA";

this._dtDataSource.Rows.Add(dr);
}

private void BindData()
{
if (this._dtDataSource == null)
{
CreateDataSource();
count++;
}

this.dgvDataGrid.DataSource = _dtDataSource;
}
private void gridviewtable_Load(object sender, EventArgs e)
{

}

private void btnAdd_Click(object sender, EventArgs e)
{
++count;
DataRow dr = this._dtDataSource.NewRow();

dr["Name"] = " Name " + count;
dr["City"] = "Delhi " + count;
dr["Country"] = "Country " + count;

this._dtDataSource.Rows.Add(dr);

this.dgvDataGrid.Refresh();
}



private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
gaurigan 26-Dec-15 7:52am View    
target application "DATAGRIDTABLE.exe" the source code is included


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinForm.Client
{
public partial class gridviewtable : Form
{ ///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// <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

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.dgvDataGrid = new System.Windows.Forms.DataGridView();
this.btnAdd = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvDataGrid)).BeginInit();
this.SuspendLayout();
//
// dgvDataGrid
//
this.dgvDataGrid.AllowUserToOrderColumns = true;
this.dgvDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvDataGrid.Location = new System.Drawing.Point(12, 70);
this.dgvDataGrid.Name = "dgvDataGrid";
this.dgvDataGrid.Size = new System.Drawing.Size(400, 150);
this.dgvDataGrid.TabIndex = 0;
this.dgvDataGrid.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(12, 12);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(149, 38);
this.btnAdd.TabIndex = 5;
this.btnAdd.Text = "Add New Row";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(322, 12);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(108, 38);
this.btnClose.TabIndex = 7;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// gridviewtable
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(442, 239);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.dgvDataGrid);
this.Name = "gridviewtable";
this.Text = "gridviewtable";
this.Load += new System.EventHandler(this.gridviewtable_Load);
((System.ComponentModel.ISupportInitialize)(this.dgvDataGrid)).EndInit();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.DataGridView dgvDataGrid;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnClose;