Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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.
 
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 21-Feb-12 23:07pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i realized that it loads the text in row editing.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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 :
 
 
/*
 * 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
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 26 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100