How to Use ComboBox in DataGridView Windows Application c#

Total Post:341

Points:2389

C#
 1009  View(s)
Ratings:
Rate this:
I want to use ComboBox in DataGridView Windows Application c#. please help me

  1. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.