C# - Add ComboBox Button CheckBox Image to dataGridView
In This C# Tutorial We will See How To :
-add Combobox To Datagridview,
-add CheckboxTo Datagridview,
-add Button To Datagridview,
-add Image To Datagridview,
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Datagridview_Add_Button_CheckBox_Combobox_Image : Form
{
public Datagridview_Add_Button_CheckBox_Combobox_Image()
{
InitializeComponent();
}
private void Datagridview_Add_Button_CheckBox_Combobox_Image_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("First Name", typeof(string));
table.Columns.Add("Last Name", typeof(string));
table.Columns.Add("Age", typeof(int));
table.Rows.Add(1, "First A", "Last A", 10);
table.Rows.Add(2, "First B", "Last B", 20);
table.Rows.Add(3, "First C", "Last C", 30);
table.Rows.Add(4, "First D", "Last D", 40);
table.Rows.Add(5, "First E", "Last E", 50);
table.Rows.Add(6, "First F", "Last F", 60);
table.Rows.Add(7, "First G", "Last G", 70);
table.Rows.Add(8, "First H", "Last H", 80);
table.Rows.Add(9, "First I", "Last I", 90);
dataGridView1.DataSource = table;
DataGridViewComboBoxColumn dcombo = new DataGridViewComboBoxColumn();
dcombo.HeaderText = "ComboBox";
dcombo.Items.Add("A");
dcombo.Items.Add("B");
dcombo.Items.Add("C");
dcombo.Items.Add("D");
DataGridViewButtonColumn dbtn = new DataGridViewButtonColumn();
dbtn.HeaderText = "Button";
DataGridViewCheckBoxColumn dchek = new DataGridViewCheckBoxColumn();
dchek.HeaderText = "CheckBox";
DataGridViewImageColumn dimg = new DataGridViewImageColumn();
dimg.Image = Properties.Resources.myico;
dimg.HeaderText = "Image";
dimg.ImageLayout = DataGridViewImageCellLayout.Stretch;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns.Add(dcombo);
dataGridView1.Columns.Add(dbtn);
dataGridView1.Columns.Add(dchek);
dataGridView1.Columns.Add(dimg);
}
}
}
=> OutPut :
Add ComboBox Button CheckBox Image to dataGridView |
Download Projects Source Code
1 comments:
commentsthanks bro
Reply