C # Form Controls DataGridView Common settings

Source: Internet
Author: User
Tags delete key

By default, the DataGridView effect is displayed:

1. Disable the last line of whitespace.

By default, the last line of whitespace represents an automatic new row, and for editing in the control, you can preserve

false;

The above disable is only the automatic new line to interact with the user interface is forbidden, but still can be through the code: DATAGRIDVIEW1.ROWS.ADD (), to add a line of blank.

2. Disable the delete function of the ' delete ' key.

By default, the mouse selects a whole row, and the delete key deletes the current entire row.

false;

The above is disabled, only the automatic new line that interacts with the user interface is forbidden, but still can be through the code:

DataGridView1.Rows.Remove (DataGridViewRow DataGridViewRow);

or dataGridView1.Rows.RemoveAt (int index);

To delete the specified row data.

3. Enable the mouse Drag and drop column function

When enabled, the order of the columns can be reordered by dragging the mouse. However, the drag-and-drop does not affect the column ordinal (keeping the original ordinal number) when the columns are accessed through code, but only shows the effect changes.

true;

4. Disable the mouse drag row height, column width

When disabled, the width of the column and the height of the row cannot be changed by mouse interaction. does not affect setting by code

false // prohibit drag column width false;    // prohibit drag row height

5. Disable the mouse drag row header (leftmost blank column) width  

// enumeration, which can be enumerated bit-adaptive size

6. Disable the cell editing feature

true;

7. Click to select the entire row, the entire column

Datagridview1.selectionmode = Datagridviewselectionmode.fullrowselect; // Click to select the entire row, enumerate

SelectionMode is an enumeration type:

Cellselect You can select one or more cells
Fullrowselect Select the entire row by clicking the header of the row or by the cells that the row contains
Fullcolumnselect Select the entire column by clicking the header of the column or by the cell that contains the column
Rowheaderselect Select this row by clicking the row's header cell. You can select this cell individually by clicking a cell.
Columnheaderselect You can select this column by clicking the header cell of the column. You can select this cell individually by clicking a cell.

8. Disable multi-line/Dole/multi-cell selection

false;

9. Set the style of grid line color of table

// set border style (top border), enumeration: Double-line inset border //  ... // Border Line Color

10. Automatic line Numbering

There is no direct setting property, you need to render the event with the control: datagridview1.cellpainting+=datagridview1_cellpainting;

        //occurs when a cell needs to be drawn.         Private voidDatagridview1_cellpainting (Objectsender, DataGridViewCellPaintingEventArgs e) {            if(E.columnindex <0&& E.rowindex >=0)//draw an auto sequence number{e.paint (e.clipbounds, Datagridviewpaintparts.all); Rectangle Vrect=E.cellbounds; Vrect.inflate (-2,2); Textrenderer.drawtext (E.graphics, (E.rowindex+1). ToString (), E.cellstyle.font, Vrect, E.cellstyle.forecolor, Textformatflags.right |textformatflags.verticalcenter); E.handled=true; }
//-----Other style settings------- if(E.rowindex%2==0) { //when the row ordinal is even (with 0)E.cellstyle.backcolor =Color.White; } Else{E.cellstyle.backcolor=Color.honeydew; } E.cellstyle.selectionbackcolor= Color.gray;//background color when cells are selectedE.cellstyle.alignment = Datagridviewcontentalignment.middlecenter;//alignment of data within a unit }

Display effect:

Http://www.cnblogs.com/CUIT-DX037/p/6909901.html

C # Form Controls DataGridView Common settings

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.