首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在WindowForm c#中设置DataGridViewTextBoxCell中的值

如何在WindowForm c#中设置DataGridViewTextBoxCell中的值
EN

Stack Overflow用户
提问于 2015-02-18 00:41:13
回答 2查看 2.2K关注 0票数 1

我无法在DataGridViewTextBox中设置值

以下是我的代码

代码语言:javascript
复制
DataGridViewTextBoxColumn tbCol = new DataGridViewTextBoxColumn();
DataGridViewTextBoxCell tbCell = new DataGridViewTextBoxCell();
tbCell.Value = "1";
tbCol.CellTemplate = tbCell;
tbCol.Name = "qtySelect";
tbCol.HeaderText = "เลือกจำนวน"; 

gridProduct.Columns.Add(tbCol);

当我运行时,添加了文本框,但它是一个空白文本框

任何人都可以帮助我。

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2015-02-18 00:47:10

您应该这样做:

代码语言:javascript
复制
yourdatagridview["columnName", rowindex].Value = "Your value";
票数 1
EN

Stack Overflow用户

发布于 2015-06-26 14:53:01

DataGridViewTextBoxColumn tbCol =新DataGridViewTextBoxColumn();DataGridViewTextBoxCell tbCell =新DataGridViewTextBoxCell();

代码语言:javascript
复制
        // Used for the appearence of the cell, it doesn't mean that there is a correlation between the cell and the column (see below ***)
        tbCell.Style.ForeColor = Color.Blue;
        tbCol.CellTemplate = tbCell;

        tbCol.Name = "qtySelect";
        tbCol.HeaderText = "Header";

        int colIndex = gridProduct.Columns.Add(tbCol);
        const int rowNumber = 0;    // define which row you want

        //Pay attention that you may need to add rows before writting to the cell
        //const int rowNumber = 1;
        //gridProduct.Rows.Add();            

        gridProduct.Rows[rowNumber].Cells[colIndex].Value = "Value for cell";

        //*** If you want to work with the cell itself, you first need to get a reference to it
        //tbCell = gridProduct.Rows[0].Cells[0] as DataGridViewTextBoxCell;
        //tbCell.Value = "1"; // and then you can overwrite the value
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28566441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档