1. How to Solve the Problem of selecting a record in the entire row
View-> optionsbehavior-> editorshowmode: Click
2. How to add a record
(1), gridview. addnewrow ()
(2) Implement the gridview_initnewrow event
3. How to solve the problem that the gridcontrol record can be obtained but not displayed
Gridview. populatecolumns ();
4. How to Make rows select but not edit (or edit a cell)
(1) view-> optionsbehavior-> editorshowmode: Click
(2) view-> optionsbehavior-> Editable: false
5. How to disable the right-click column in gridcontrol
Set run design-> optionsmenu-> enablecolumnmenu to: false
6. How to hide the grouppanel header of gridcontrol
Set run design-> optionsview-> showgrouppanel to: false
7. shows how to disable the filter of the column header in gridcontrol:
Set run design-> optionscustomization-> allowfilter to: false
8. How to display the custom character prompt/display when the query gets 0 records:
The method is as follows:
// When no records are being displayed
Private void gridview1_mdmdrawemptyforeground (Object sender, customdraweventargs E)
{
// Method 1 (this method is available when data source binding is set for the gridview)
Columnview = sender as columnview;
Bindingsource = This. gridview1.datasource as bindingsource;
If (bindingsource. Count = 0)
{
String STR = "No data is found! ";
Font F = new font ("", 10, fontstyle. Bold );
Rectangle r = new rectangle (E. bounds. Top + 5, E. bounds. Left + 5, E. bounds. Right-5, E. bounds. Height-5 );
E. Graphics. drawstring (STR, F, brushes. Black, R );}
// Method 2 (this method is used when the data source binding is not set for the gridview. This method is generally used)
If (this. _ flag)
{If (this. gridview1.rowcount = 0)
{String STR = "No data is found! "; Font F = new font (" ", 10, fontstyle. Bold );
Rectangle r = new rectangle (E. bounds. Left + 5, E. bounds. Top + 5, E. bounds. Width-5, E. bounds. Height-5 );
E. Graphics. drawstring (STR, F, brushes. Black, R );}}}
9. How to display the horizontal scroll bar? Or
Set this. gridview. optionsview. columnautowidth = false;
... List width adaptive content
Gridview1.bestfitcolumns ();
10. How to locate the first data/record?
Set this. gridview. movefirst ()
11. How to locate the next data/record? Set this. gridview. movenext ()
12. How to locate the last data/record?
Set this. gridview. movelast ()
13. Set to select a row at a time and cannot be edited
This. gridview1.focusrectstyle = devexpress. xtragrid. Views. Grid. drawfocusrectstyle. rowfocus;
This. gridview1.optionsbehavior. editable = false;
This. gridview1.optionsselection. enableappearancefocusedcell = false;
14. How do I display the row number? Private void gvpaylist_customdrawrowindicator (Object sender, devexpress. xtragrid. views. grid. rowindicatorcustomdraweventargs e) {e. appearance. textoptions. halignment = devexpress. utils. horzarignment. far; If (E. info. isrowindicator) {If (E. rowhandle> = 0) {e. info. displaytext = (E. rowhandle + 1 ). tostring ();} else if (E. rowhandle <0 & E. rowhandle>-1000) {e. info. appearance. backcolor = system. drawing. color. antiquewhite; E. info. displaytext = "G" + E. rowhandle. tostring ();}}}
15. How can I disable the movement of column headers?
Set gridview1.optionscustomization. allowcolumnmoving = false;
16. How can I disable the sorting of column headers?
Set gridview1.optionscustomization. allowsort = false;
17. How can I disable different column headers from changing the column width?
Set gridview1.optionscustomization. allowcolumnresizing = false;
18. Fixed a column when dragging the scroll bar
| Set columns and select the columns to be fixed. Set the fixed attribute. You can choose to set the attribute to left, right, or left. |
19. Get the selected row and specify the Column cell content
Return gridview1.getrowcellvalue (prows [0], columname). tostring ();
20. group display
Optionsview> optionsbehavior> autoexpandallgroups = true: select the column to be grouped and set the groupindex attribute to 0.
21. format data
Private void gvlist_validatingeditor (Object sender, devexpress. xtraeditors. controls. basecontainervalidateeditoreventargs e) {If (this. gvlist. focusedcolumn. fieldname = "passqty") {string passqty = E. value. tostring (). trim (); int receiveqty = orderdetaillist [this. gvlist. focusedrowhandle]. qty; If (! Jxtype. isintbigthanzero (passqty) {e. Valid = false; E. errortext = "the number of accepted items must be an integer greater than or equal to 0 and less than or equal to the number of received items! ";} Else {If (Int. parse (passqty)> receiveqty) {e. valid = false; E. errortext = "the number of eligible items must be an integer greater than 0 and less than or equal to the number of received items! ";}}}
}
22. Merge the header
/// Initialize the table
Using devexpress. xtragrid. columns; using devexpress. xtragrid. views. base; using devexpress. xtragrid. views. bandedgrid; using devexpress. xtraeditors. repository; private void initgrid () {// advbandedgridview1 is the default view on the table. Note that: bandedgridview view = advbandedgridview1 as bandedgridview; view. beginupdate (); // start view editing to prevent other Event Views from being triggered. begindataupdate (); // start the data editing view. bands. clear ();
View. optionsview. showcolumnheaders = false; // The columnheader is hidden because of the band column. // Add a column title
Gridband bandid = view. bands. addband ("ID"); bandid. Visible = false; // hide the ID column
Gridband bandname = view. bands. addband ("name"); gridband bandsex = view. bands. addband ("gender"); gridband bandbirth = view. bands. addband ("Date of Birth"); gridband bandscore = view. bands. addband ("score"); gridband bandmath = bandscore. children. addband ("Mathematics"); gridband bandchinese = bandscore. children. addband (""); gridband bandenglish = bandscore. children. addband ("English"); gridband bandsubtotal = bandscore. children. addband ("subtotal"); gridband bandremark = view. bands. addband ("Remarks ");
Bandfile. appearanceheader. textoptions. halignment = devexpress. utils. horzarignment. center; // This is the center view of the merged header. enddataupdate (); // edit view of end data. endupdate (); // edit the end view}
For details, see
Dev gridcontrol merge Header
23. // Add the devexpress column dynamically. xtragrid. columns. gridcolumn col1 = new devexpress. xtragrid. columns. gridcolumn (); col1.fieldname = "name"; col1.caption = "name"; col1.visible = false; col1.visibleindex = gvcountry. columns. count; gvcountry. columns. add (col1 );
24. Set the automatically added row number
Private void gridview_customdrawrowindicator (Object sender, devexpress. xtragrid. Views. Grid. rowindicatorcustomdraweventargs e ){
E. appearance. textoptions. halignment = devexpress. utils. horzarignment. far; If (E. info. isrowindicator) {If (E. rowhandle> = 0) {e. info. displaytext = (E. rowhandle + 1 ). tostring ();} else if (E. rowhandle <0 & E. rowhandle>-1000) {e. info. appearance. backcolor = system. drawing. color. antiquewhite; E. info. displaytext = "G" + E. rowhandle. tostring ();}}
}
25. Special Effects: There are five view types in gridcontrol: the common view type is gridview, Which is cardview, bandedview, advanced bandedview, and layoutview respectively. There are five view types.
1) in the view group, set the viewmode under optionview to "Carousel usel" to achieve this type of "Carousel" gridcontrol view effect. 2) layoutview1.optionscarouselmode. the pitchangle attribute determines the pitch angle of the "Carousel", the spiral angle, the spiral angle, the pitch angle, the inclination angle, and the half angle of the cone. 3) The roll angle attribute determines the tilt angle. 4), specified data source, display data: // display data private void showdata (list <employee> List) {datatable dt = new datatable ("oneemployee"); DT. columns. add ("caption", system. type. getType ("system. string "); DT. columns. add ("department", system. type. getType ("system. string "); DT. columns. add ("photoname", system. type. getType ("system. byte [] ");
For (INT I = 0; I <list. count; I ++) {datarow DR = DT. newrow (); Dr ["caption"] = list [I]. name; Dr ["department"] = list [I]. department; string ImagePath = @ "D: \ C # \ photos \" + list [I]. photopath; Dr ["photoname"] = getimagebyte (ImagePath); DT. rows. add (DR);} gridcontrol1.datasource = DT ;}
// Returns the byte stream byte [] private byte [] getimagebyte (string ImagePath) {filestream files = new filestream (ImagePath, filemode. open); byte [] imgbyte = new byte [files. length]; files. read (imgbyte, 0, imgbyte. length); files. close (); Return imgbyte ;}
26. Check the Data Validity
Add check code in the validaterow event of the gridview: # region check data private void gridview1_validaterow (Object sender, validateroweventargs e) {gridview view = sender as gridview; view. clearcolumnerrors ();
If (view. getrowcellvalue (E. rowhandle, "receivedate") = dbnull. value) {e. valid = false; view. setcolumnerror (view. columns ["receivedate"], "date must be specified ");}
}
27. set gridview1.columns to display in a column of text and title [0]. appearanceheader. textoptions. halignment = devexpress. utils. horzarignment. center; gridview1.columns [0]. appearancecell. textoptions. halignment = devexpress. utils. horzarignment. center;
28. Multiple filtering conditions in the list
Column name. optionsfilter. filterpopupmode = devexpress. xtragrid. Columns. filterpopupmode. checkedlist
29. Method for changing the color of the line
This. gridview1.appearance. oddrow. backcolor = color. white; // set the color of an odd number of rows. // This can be omitted if the color is white by default. gridview1.optionsview. enableappearanceoddrow = true; // enable // use this when binding with the above. gridview1.appearance. evenrow. backcolor = color. whitesmoke; // set the color of the even row this. gridview1.optionsview. enableappearanceevenrow = true; // enable // valid when used together with the above binding