Datagridview format-Initial Release

Source: Internet
Author: User

Datagridview format -- Initial Release

 

Vs2005 provides the following 6 types for us. The first three of them are automatically generated as long as they are set to the corresponding field type, the last three data items must be manually set. in addition, we can also customize the form and column format.

1. Column expression provided by vs2005

-- 1. datagridviewtextboxcolumn
Use it with the text-based delimiter value. When a string is reached, it is automatically generated.

In quiet mode, a textbox is displayed in the previous cell, used to modify the value in the cell.

The value of a single element indicates a string automatically displayed. Automatically analyzes the value imported or modified by the user to create a metadata value for the user. You can customize these parameters by controlling the cellformatting and cellparsing events of the topology through the processing datagridview.

The single element value type of each column can be specified in the valuetype category of each column, but it does not seem to exist in the textbook window, you need to configure it in the agent.

-- 2. datagridviewcheckboxcolumn
Use with Boolean and checkstate values. When these values are reached, they are automatically generated.

The Boolean value depends on the value of threestate encoding, which indicates that the two operators or three operators have the same number of operators. When the data row ends to the checkstate value, the value of threestate encoding is set to true in the root response.

Usually, the goal of obtaining the vertex value is to store (for example, any other information) or perform a large number of operations. If you want to immediately respond to the cellclick event when the user clicks the single cell of the last vertex, The cellclick event can be handled, but this event occurs before updating the single cell value. If you need a new value when you press it, one option is the current value of the root node. Another method is to recognize changes immediately and process the cellvaluechanged event to make a response. To change the status of a single cell, you must handle the currentcelldirtystatechanged event. In the processing regular formula, if the current single cell is the kernel cell, call the commitedit method and merge it into the commit value.

-- 3. datagridviewimagecolumn
Used to display a video clip. When the elements, image objects, or icon objects are reached, they are automatically generated.
The auto-filling of the source metadata row enables the bitwise grouping columns in various image formats, including all formats supported by image, and the format of OLE snapshots for access and northwind instances.

In addition to the dynamic filling of data sources, you can also manually enter the unpaid data rows or customize the cellformatting event.

You can handle the system. Windows. Forms. dview. cellclick event to respond to the selected action in a single cell.

When you want to provide a clip for a calculated value or a value in a non-sliced format, fill in the cell of the raw row in the Processing Formula of the cellformatting event, is a useful method. For example, you may have a "Response Message", which contains "high", "Middle", "low", and other string values that you want to display as values. In addition, there may also be "snapshots", which contain the locations of the necessary clips, rather than the binary content of the clips.

-- 4. datagridviewbuttoncolumn
Use to calculate the order in the unit cell. It cannot be automatically generated at the end of the lifecycle. It is usually used as a non-final data row.
It can be seen as an example of the datagridviewimagecolumn.

You can handle the system. Windows. Forms. dview. cellclick event and apply the user's selected actions in the worksheet.

-- 5. datagridviewcomboboxcolumn
Used to show the drop-down list in the single cell. It cannot be automatically generated at the end of the lifecycle. Resources are usually manually linked.

You can fill in the ComboBox drop-down list in the same way, fill in the drop-down list for all units: (1) one method is the set that passes through the items compile response, (2) The other method is to link the data source, displaymember, and valuemember to the data source.

You can configure the datapropertyname of the system. Windows. Forms. datagridviewcomboboxcolumn to set the object metadata used by the datagridview.

-- 6. datagridviewlinkcolumn
Used to display the results in a single cell. It cannot be automatically generated at the end of the lifecycle. Resources are usually manually linked.

You can handle the cellcontentclick event and apply the selected actions to the user. This event is different from the cellclick and cellmouseclick events. The last two events occur at any location in the user's selected cell.

The datagridviewlinkcolumn type does not provide data consistency. You can modify the outer region of the selected link before, during, and after the selected link.

2. Self-partitioning Columns
The method is to first create a custom datagridviewcell, which is derived from the base class or one of the derivative classes of the datagridviewcell. then inherit the datagridviewcolumn class or one of its derivative classes to provide the column's self-export, row-based, or dynamic control.

The following is a complete example. It will establish a self-contained cell type similar to the datagridviewrolovercell. This type will not limit when the mouse enters or opens the cell line. When the mouse is placed in a single cell's border, it will draw a concave box. In addition, a matching column format is used as the datagridviewrolovercolumn.

 

Using system;
Using system. drawing;
Using system. Windows. forms;

Class form1: Form
{
[Stathreadattribute ()]
Public static void main ()
{
Application. Run (New form1 ());
}

Public form1 ()
{
Datagridview datagridatagri1 = new datagridview ();
Maid =
New maid ();
Datagridview1.columns. Add (COL );
Datagridview1.rows. Add (New String [] {""});
Datagridview1.rows. Add (New String [] {""});
Datagridview1.rows. Add (New String [] {""});
Datagridview1.rows. Add (New String [] {""});
This. Controls. Add (datagridview1 );
This. Text = "maid-cell Demo ";
}
}

Public class maid: maid
{
Protected override void paint (
Graphics graphics,
Rectangle clipbounds,
Rectangle cellbounds,
Int rowindex,
Maid cellstate,
Object value,
Object formattedvalue,
String errortext,
Datagridviewcellstyle cellstyle,
Datagridviewadvancedborderstyle advancedborderstyle,
Datagridviewpaintparts paintparts)
{
// Call the base class method to paint the default cell appearance.
Base. Paint (graphics, clipbounds, cellbounds, rowindex, cellstate,
Value, formattedvalue, errortext, cellstyle,
Advancedborderstyle, paintparts );

// Retrieve the client location of the mouse pointer.
Point cursorposition =
This. datagridview. pointtoclient (cursor. position );

// If the mouse pointer is over the current cell, draw a custom border.
If (cellbounds. Contains (cursorposition ))
{
Rectangle newrect = new rectangle (cellbounds. x + 1,
Cellbounds. Y + 1, cellbounds. Width-4,
Cellbounds. Height-4 );
Graphics. drawrectangle (pens. Red, newrect );
}
}

// Force the cell to repaint itself when the mouse pointer enters it.
Protected override void onmouseenter (INT rowindex)
{
This. datagridview. invalidatecell (this );
}

// Force the cell to repaint itself when the mouse pointer leaves it.
Protected override void onmouseleave (INT rowindex)
{
This. datagridview. invalidatecell (this );
}

}

Public class maid: maid
{
Public maid ()
{
This. celltemplate = new maid ();
}
}

3. Regionalization of the datagridview
To display a large number of data records, follow these steps.
Http://technet.microsoft.com/zh-tw/library/ha5xt0d9 (vs.80). aspx

Http://technet.microsoft.com/zh-tw/library/bxt3k60s (vs.80). aspx

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.