简体   繁体   English

如何向DataGridView TextBox添加隐藏值? (C#)

[英]How to add a hidden value to DataGridView TextBox? (C#)

I am working with an existing GridView and I want to know if there is a way I can have a different value and display for the TextBoxColumn, similar to a ComboBoxColumn (displaymember, valuemember). 我正在使用现有的GridView,我想知道是否有一种方法可以使TextBoxColumn具有不同的值和显示,类似于ComboBoxColumn(displaymember,valuemember)。

private System.Windows.Forms.DataGridViewTextBoxColumn PATH;

 this.PATH.DataPropertyName = "Path";
 this.PATH.HeaderText = "PATH";
 this.PATH.Name = "Path";
 this.PATH.ReadOnly = true;
 this.PATH.Width = 186;

Right now I have a hidden column with the ID but I am wondering if there is a better solution. 现在,我有一个带有ID的隐藏列,但我想知道是否有更好的解决方案。

ETA: I have put PATH.DataPropertyName = "PathId" (the hidden value I want to use for update) and this.PATH.Name = "Path" (The string value I want displayed) 预计到达时间:我已将PATH.DataPropertyName =“ PathId”(我要用于更新的隐藏值)和this.PATH.Name =“ Path”(我要显示的字符串值)放入

The Name value is still returned when I get the value of the column. 当我获得列的值时,仍然返回Name值。

this.mySampleGridView.Rows[i].Cells["Path"].Value this.mySampleGridView.Rows [i] .Cells [“ Path”]。Value

DataPropertyName should help here, if I understand the question correctly. 如果我正确理解了这个问题,DataPropertyName应该可以在这里提供帮助。

From the MSDN documentation about DataGridViewColumn.DataPropertyName: 从有关DataGridViewColumn.DataPropertyName的MSDN文档中:

// Initialize and add a text box column.
DataGridViewColumn column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "Name";
column.Name = "Knight";
dataGridView1.Columns.Add(column);

The column is now bound to an item that has multiple pieces of information but is only showing one piece. 现在,该列已绑定到一个具有多条信息但仅显示一条信息的项目。 The rest is effectively hidden. 其余的被有效隐藏。

EDIT: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx 编辑: http//msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM