In this Discussion,I explaining about Display “ ComboBox “ Field In GridView and also Create a table Data without DataBase Creation and Displays in GridView as image shown below….
-Drog and Drop one Gridview and one button control from ToolBox in Windows form,then write the code like shown below :
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 GridViewWithComboBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
<!-- Create a table Data without DataBase Creation and Displays in GridView… -->(comment)
private void button1_Click(object sender, EventArgs e) // button click event
{
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
<!-- Below Code is for Display “ ComboBox “ Field in GridView -->(comment)
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.HeaderText = "Select Data";
cmb.Name = "cmb";
cmb.MaxDropDownItems = 4;
cmb.Items.Add("True");
cmb.Items.Add("False");
dataGridView1.Columns.Add(cmb);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}

No comments:
Post a Comment