HOW TO CREATE COLUMNS IN DATAGRIDVIEW WINDOWS APPLICATION IN C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#
 429  View(s)
Ratings:
Rate this:
I want to Create Columns in DataGridView Windows Application in c#. please Help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to Create Columns in DataGridView Windows Application in c#

    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()
            {
                InitializeComponent();
            }

            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)
            {
                CreateColumn();
            }

             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);
             }      
           
        }
    }

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!