无法在DataGridViewButtonColumn中显示文本

时间:2017-05-05 12:02:59

标签: c# datagridview datagridviewbuttoncolumn

我尝试使用“DataGridViewButtonColumn”属性练习。

但是这是一个奇怪的问题,我无法在第一列的按钮中显示文本。

ScreenShot:

我用不同的方法尝试,但它仍然无效。

这是我的代码段。

谢谢^ __ ^

login() : void {
        let _authenticationResult: OperationResult = new OperationResult(false, '');
        this.dataService.login({username: this._user.username, password: this._user.password}).subscribe((result: any) => {
            _authenticationResult.succeeded = result.succeeded;
            _authenticationResult.message = result.message;

            if(_authenticationResult.succeeded) {
                this.notificationService.printSuccessMessage('Welcome ' + this._user.username + '!');
                localStorage.setItem('user', JSON.stringify(this._user));
                this.router.navigate(['/list']);
            } else {
                this.notificationService.printErrorMessage(_authenticationResult.message);
            }
        }),
        error => console.error('Error: ' + error);
    }

1 个答案:

答案 0 :(得分:3)

阅读DataGridViewButtonColumn.UseColumnTextForButtonValue

将值设置为false以获得所需的结果:

this.Column1.UseColumnTextForButtonValue = false;

将其设置为true意味着它将为每个按钮的文本值(您未设置的文本值)使用DataGridViewButtonColumn.Text - 因此在所有按钮上显示空白文本。例如:

this.Column1.UseColumnTextForButtonValue = true;
this.Column1.Text = "Click Here";

10 "Click Here" buttons

相关问题