简体   繁体   English

C#Windows窗体Datagridview单元格显示文本

[英]c# windows form datagridview cell display text

I bind the datagrid from the data i get from the database using code as below 我使用下面的代码将我从数据库获得的数据绑定到数据网格

dgvName.Datasource = ds.Table[0]; dgvName.Datasource = ds.Table [0];

The data as below 数据如下

Id      Name       Active
1       Test       1
2       Test1      0
3       Test3      0

I wish to display the active as "Y" or "No" instead of 1 or 0. I try CellFormatting handler but it's not work. 我希望将活动显示为“ Y”或“ No”,而不是1或0。我尝试使用CellFormatting处理程序,但是它不起作用。 Active datatype is int. 活动数据类型为int。 How I can do that? 我该怎么做? Please help. 请帮忙。

The simplest you could think is: Add a new property on your class, for example 您可能想到的最简单的方法是:例如,在类上添加新属性

public string ActiveText 
  {
     get { return _active ? "Y" : "N"; } 
  }

and bind it to column you want 并将其绑定到您想要的列

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

相关问题 在 datagridview 组合框中选择在另一个单元格中显示图像 c# windows 形式 - selection in datagridview comboboxcolumn display image in another cell c# windows form 在DataGridView C#Windows窗体中单击时获取单元格的位置 - Getting the location of cell when clicked in DataGridView C# windows form C#DataGridView和Windows窗体 - C# DataGridView and Windows Form 以C#Windows形式从DataGridView写入文本文件 - Writing to a text file from DataGridView in C# windows form 在datagridview c#中仅选择单元格的文本 - Select only a text of cell in datagridview c# 在 C# 中对 dataGridView 列进行排序? (Windows 窗体) - Sort dataGridView columns in C# ? (Windows Form) 将日期类型的DataGridView单元格值传递给DateTimePicker的C#Windows窗体 - C# Windows Form Passing DataGridView Cell Value of type Date to DateTimePicker DataGridView到Windows Forms C#上的文本文件 - DataGridView to text file on Windows Forms C# 如何在C#中将文本从From2传输到Form1中的dataGridView单元格 - How to transfer text from From2 to dataGridView cell in Form1 in C# 来自Windows窗体(C#)中存储在数据库(sqlite)中的图像路径的datagridview中的图像显示问题 - Image display issue in datagridview from imagepath stored in database(sqlite) in windows form(C#)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM