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