DataGridViewButtonColumn文字问题 [英] DataGridViewButtonColumn text problem

查看:85
本文介绍了DataGridViewButtonColumn文字问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有一个问题,列中的按钮不继承列文本.我写了一些虚拟代码来测试我的目标...请帮助我,告诉我是否有任何遗漏.

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);
        }

推荐答案

我意识到它会在行编辑中加载文本.
i realized that it loads the text in row editing.


您好,
我已经在Microsoft .Net Framework 2.0 SDK文档中找到了这个
这种代码的安宁性为所有已创建的dataGridView1表添加了一个按钮列
并将列的名称设置为销售",并将按钮的名称设置为相同的值.

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);
}



因此,我在设计器(设计视图)中仅用一个datagridView1表创建了简单的Windows Form应用程序,该表具有两列,并且添加了以下代码:



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);

		}

	}
}




现在,它执行此操作,显示具有三列,十行的DataGridView表
和按钮列具有提示的文本和按钮名称.

如果在程序开始时未声明dataGridView应该有多少行,则在程序启动时,按钮上将只有一行,没有名称.

祝一切顺利
PerićŽeljko




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


这篇关于DataGridViewButtonColumn文字问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆