简体   繁体   中英

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

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. Active datatype is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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