How does the winforms DataGrid display bool field values as text? Yes/No [reprint]

Source: Internet
Author: User
How does the winforms DataGrid display bool field values as text? Yes/No [reprint]

Method 1:
If your SQL is like this
Select boolfield, textfield from xxxtable where ....
Then change
Select (cast when boolfield 1 then 'is 'else' no' end) as boolfieldex, textfield from xxxtable where ....

That is to say, in the record set, convert the bool type field to the text type field.

Method 2:

All columns are specified as datagridtextboxcolumn. If you do not add a datagridtablestyle, The DataGrid will be automatically allocated based on the field type after the data source is set, the only thing you need to do is to specify the style of each column as the code below. In addition, the column style of the DataGrid only supports the Boolean and text types.
// Creation Style
Datagridtablestyle dbts =   New Datagridtablestyle ();
// Your field 1 Style
System. Windows. Forms. datagridtextboxcolumn Column =   New Datagridtextboxcolumn ();
Column. nulltext =   "" ;
Column. headertext =   " Your field title name 1 " ;
Column. mappingname =   " Your field name 1 " ;
Column. Width = 100 ;
Dbts. gridcolumnstyles. Add (column );
// Your field 2 style
System. Windows. Forms. datagridtextboxcolumn Column =   New Datagridtextboxcolumn ();
Column. nulltext =   "" ;
Column. headertext =   " Your field title name 2 " ;
Column. mappingname =   " Your field name 2 " ;
Column. Width = 100 ;
Dbts. gridcolumnstyles. Add (column );
// Join Style
DataGrid. tablestyles. Clear ();
DataGrid. tablestyles. Add (dbts );

You can assign a Boolean field column to the datagridtextboxcolumn without the datagridboolcolumn style.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.