Home > DeveloperSection > Forums > How to Create Columns in DataGridView Windows Application in c#
Ankit Singh

Total Post:341

Posted on    December-13-2015 10:11 PM

 C# C#  Windows Controls  Datagridview 

 1 Reply(s)
 205  View(s)
Rate this:
I want to Create Columns in DataGridView Windows Application in c#. please Help me.

aditya kumar Patel

Total Post:250

Posted on    December-13-2015 10:23 PM

The DataGridView control makes it easy to define the basic appearance of cells and the display formatting of cell values. The cell is the fundamental unit of interaction for the DataGridView. All cells derive from the DataGridViewCell base class. Each cell within the DataGridView control can have its own style, such as text format, background color, foreground color, and font. Typically, however, multiple cells will share particular style characteristics. The data type for the cell's Value property by default is of type Object.

using System;
using System.Collections.Generic;
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;
using System.IO;
using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.Data;
namespace WindowsForums
    public partial class Form1 : Form
        public Form1()

        private void CreateColumn()
            dataGridView1.Columns.Add("id", "ID");
            dataGridView1.Columns.Add("productname", "ProductName");
            dataGridView1.Columns.Add("quantity", "Quantity");
            dataGridView1.Columns.Add("rate", "Rate");
            dataGridView1.Columns.Add("amount", "Amount");

        private void Form1_Load(object sender, System.EventArgs e)

         private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
           int index=e.RowIndex;
           decimal quantity=Convert.ToDecimal( dataGridView1.Rows[index].Cells["quantity"].Value);
           decimal rate = Convert.ToDecimal(dataGridView1.Rows[index].Cells["rate"].Value);
            dataGridView1.Rows[index].Cells["amount"].Value = (quantity * rate);


Don't want to miss updates? Please click the below button!

Follow MindStick