Improvement of DATAGRIDTEXTBOX similar to BOOLEAN Columns

Source: Internet
Author: User

Here we will talk about how to perform data column Content and Display operations.

This method is similar to the implementation: a data table exists.Test (id int not null primary key, name varchar (20), sex bit ),Is there a way to directly use it without passing through?SQLStatement, such:Select id, name, sex = case sex (when true then'Male'When false then'Female'Else sex end)In the formTrueAndFalseWhat about it? Of course, if we useDatagridboolcolumnBy setting some of its attributes (Truevalue, falsevalue) Can achieve similar results, but for thoseBitWhat about columns? The answer is yes. We use inheritanceDatagridtextboxcolumnClass, and then overrideGetColumnValueAtRowMethod To achieve the effect.GetColumnValueAtRowMethod to retrieve the data from the data source, and then return the value we want to display in the grid. (For the code, see the detailed code below)

In this way, we can smoothly display the desired data in the grid, but there is another problem: if we want to modify the data in the grid, can it be submitted to the database? If you only use the above operation to achieve the purpose of display, you must rewrite it.Edit, commit,AbortMethod To modify the content after clicking the cell, submit the changes, and update the changes to the database.

The following is the complete code of the program. I hope you can make improvements as needed.

**************************************** ***********************************

Program name:CanSetValueDatagridTextbox

Function Description: inherited fromDatagridtextboxcolumnClass Column Style, mainly to display and update the display value and actual value

Related Article

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.