Adding a checkbox to the grid
Run Desiger
Columns
Select checkbox in Columnedit
At this point, we want to manually specify a data column in the background code like this:
DTREBATESREPORT.COLUMNS.ADD ("Mutiselect", System.Type.GetType ("System.Boolean")). DefaultValue =false; DTREBATESREPORT.COLUMNS.ADD ("PAYMENTSTATE1", System.Type.GetType ("System.Boolean")). DefaultValue =false; for(inti =0; i < DtRebatesReport.Rows.Count; i++) {DataRow Dr=Dtrebatesreport.rows[i]; if(dr["paymentstate"]. ToString () = ="0") {dr["PAYMENTSTATE1"] =false; } Else{dr["PAYMENTSTATE1"] =true; } }
Backstage here if the return is an int data, be sure to manually turn bool back to true is not available.
Grid. Getrowcellvalue (i,columnsname)//Get the specified cell file
Grid. Setrowcellvalue (I,columnsname,value)//Set cell transfer
If Gird is joined Combox find the Combox name. Initialize directly to a value
We can tell if we can edit it as follows
/// <summary> ///If the row focus changes, can be edited to delete/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidGvincomedetailreport_focusedrowchanged (Objectsender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {GridView GV= Sender asGridView; if(E.focusedrowhandle >=0) { BOOLCanEdit = Convert.toboolean (GV. Getrowcellvalue (E.focusedrowhandle, This. GridColumn16)); if(canedit) {//not editable when paid This. GridColumn11.OptionsColumn.AllowEdit =false; This. GridColumn12.OptionsColumn.AllowEdit =false; This. GridColumn14.OptionsColumn.AllowEdit =false; This. GridColumn15.OptionsColumn.AllowEdit =false; } Else { This. GridColumn11.OptionsColumn.AllowEdit =true; This. GridColumn12.OptionsColumn.AllowEdit =true; This. GridColumn14.OptionsColumn.AllowEdit =true; This. GridColumn15.OptionsColumn.AllowEdit =true; } } }
View Code
Here we can calculate when we change the value of a cell
Private voidGvincomedetailreport_cellvaluechanging (Objectsender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { //Select column Value change if(E.column = = This. GridColumn11) { if(!Commonutils.isempty (commonutils.objecttostring (e.value))) { //Discount Amount stringStr1=commonutils.objecttostring (Gvincomedetailreport.getrowcellvalue (E.rowhandle, This. gridColumn9)); stringSTR2 =commonutils.objecttostring (E.value); stringMoney =string. IsNullOrEmpty (str1)?"0": str1; stringSendmoney =string. IsNullOrEmpty (str2)?"0": str2; decimalV1, V2 =0; decimalZkmoney =0; if(decimal. TryParse (Money, outv1)) {Zkmoney=v1; } decimalCellmoney =0; if(decimal. TryParse (Sendmoney, outv2)) {Cellmoney=v2; } gvincomedetailreport.setrowcellvalue (E.rowhandle, This. gridcolumn14,zkmoney+Cellmoney); } } }
View Code
Set cell color as follows
Private voidGvincomedetailreport_rowcellstyle (Objectsender, Rowcellstyleeventargs e) {GridView GV= Sender asGridView; if(E.rowhandle >=0) { BOOLCanEdit = Convert.toboolean (GV. Getrowcellvalue (E.rowhandle, This. GridColumn16)); if(canedit) {E.appearance.backcolor=Color.lightgray; } Else { //gets the value of the specified column in the row stringState = This. Gvincomedetailreport.getrowcellvalue (E.rowhandle,"Mutiselect"). ToString (); //compare the state of a specified column if(state = ="True") {E.appearance.backcolor= Color.blueviolet;//set the background color of this line } Else{E.appearance.backcolor= Color.White;//set the background color of this line } } } }
View Code
Totals the column values
decimal_customsum =0; Private voidGvincomedetailreport_customsummarycalculate (Objectsender, DevExpress.Data.CustomSummaryEventArgs e) {GridView GridView= Sender asGridView; DataRow Dr=Gridview.getdatarow (E.rowhandle); if("Rebateamount". Equals ((E.item asGridsummaryitem)) | |"Adjustmentamount". Equals ((E.item asGridsummaryitem). FieldName) | |"Actualamount". Equals ((E.item asGridsummaryitem). FieldName)) {if(! Commonutils.isempty (Commonutils.objecttostring (dr[(e.item asGridsummaryitem). FieldName])) {_customsum+ = Convert.todecimal (dr[(e.item asGridsummaryitem). FieldName]); } e.totalvalue=_customsum; } }
View Code
Use of grid in Dexpress