HOW TO USE COMBOBOX IN DATAGRIDVIEW WINDOWS APPLICATION C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#
 497  View(s)
Ratings:
Rate this:
I want to use ComboBox in DataGridView Windows Application c#. please help me

  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to Use ComboBox in DataGridView Windows Application c#

    The DataGridView control is highly configurable and extensible, and it provides many properties, methods, and events to customize its appearance and behavior. The DataGridView control makes it easy to define the basic appearance of cells and the display formatting of cell values.

    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. You can define appearance and formatting styles for individual cells, for cells in specific columns and rows, or for all cells in the control by setting the properties of the DataGridViewCellStyle objects accessed through various DataGridView control properties.

    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()
            {
                DataGridViewComboBoxColumn dvgcmb = new DataGridViewComboBoxColumn();
                dvgcmb.HeaderText = "Product Name";
                dvgcmb.Name = "productname";
                dvgcmb.Items.Add("Computer");
                dvgcmb.Items.Add("Mobile");
                dvgcmb.Items.Add("Laptop");
                dvgcmb.Items.Add("Mouse");
                dvgcmb.Items.Add("Keyboard");

                dataGridView1.Columns.Add("id", "ID");
                dataGridView1.Columns.Add(dvgcmb);
                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!