Hello,
I have found this in Microsoft .Net framework 2.0 SDK documentation
This peace of code adds one button column to allready created dataGridView1 table
and sets the name of column to "Sales" and name of the button to the same value.
private void AddButtonColumn()
{
DataGridViewButtonColumn buttons = new DataGridViewButtonColumn();
{
buttons.HeaderText = "Sales";
buttons.Text = "Sales";
buttons.UseColumnTextForButtonValue = true;
buttons.AutoSizeMode =
DataGridViewAutoSizeColumnMode.AllCells;
buttons.FlatStyle = FlatStyle.Standard;
buttons.CellTemplate.Style.BackColor = Color.Honeydew;
buttons.DisplayIndex = 0;
}
dataGridView1.Columns.Add(buttons);
}
So I have made simple Windows Form Application with only one datagridView1 table in the designer (design view) with two columns and I have added this code :
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Test_aplikacija
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
dataGridView1.RowCount = 10;
Column1.HeaderText = "Confirm Sales";
Column1.Text = "Confirm Button";
Column1.UseColumnTextForButtonValue = true;
AddButtonColumn();
dataGridView1.Refresh();
}
private void AddButtonColumn()
{
DataGridViewButtonColumn buttons = new DataGridViewButtonColumn();
{
buttons.HeaderText = "Sales";
buttons.Text = "Sales";
buttons.UseColumnTextForButtonValue = true;
buttons.AutoSizeMode =
DataGridViewAutoSizeColumnMode.AllCells;
buttons.FlatStyle = FlatStyle.Standard;
buttons.CellTemplate.Style.BackColor = Color.Red;
buttons.DisplayIndex = 0;
}
dataGridView1.Columns.Add(buttons);
}
}
}
So now it do this , shows DataGridView table with three columns, with ten rows
and button columns have heder text and button names as it shuld have.
If you do not declare how many rows should dataGridView have at the beginning of program , when program starts you shall have only one row with no names on the buttons.
All the best
Perić Željko