Click here to Skip to main content
15,883,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys
i am having a problem that buttons in the columns don't inherit the column text . i wrote some dummy code to test my goal ... please help me and tell if there anything missing.

C#
private void Form1_Load(object sender, EventArgs e)
        {
            DataGridViewButtonColumn DGVBC = new DataGridViewButtonColumn();
            DGVBC.HeaderText = "view";
            DGVBC.Text = "view";
            DGVBC.UseColumnTextForButtonValue = true;
            dataGridView1.Columns.Add(DGVBC);
        }
Posted

i realized that it loads the text in row editing.
 
Share this answer
 
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.

C#
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 :

C#
/*
 * Created by SharpDevelop.
 * User: Perić Željko
 * Date: 24.02.2012
 * Time: 12:57
 * 
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Test_aplikacija
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// Set initial number of rows in dataGridView1 to 10
			//
			dataGridView1.RowCount = 10;
			//
			// Set Column1 Heder Text and Buttons name to "Confirm Sales"
			//
			Column1.HeaderText = "Confirm Sales";
			Column1.Text = "Confirm Button";
			Column1.UseColumnTextForButtonValue = true;
			//
			// Add button column called "Sales"
			//
			AddButtonColumn();
			//
			// Refresh dataGridView1
			//
			dataGridView1.Refresh();
		}
		
		//
		// Add button column called Sales with the same name of buttons
		// as the first column
		//
		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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900