Feel the convenience of DataGrid to data operation (2)

xiaoxiao2021-03-06  76

Section 2: Customize the appearance of DataGrid

In the previous article, I prelimated the convenience of DataGrid to me, but if it is the form of the program drawing the program, we can make a flexible control form of expression, so DataGrid can customize it. Manifestations. Answer, I know that it is ok, the key is whether it is coming than my own code "painting".

Based on past experience, I know that these operations can be completed from the attributes of DataGrid.

1. Select the columns to display:

In the default, our columns we displayed in the DataGrid are the columns we queried when we execute SQL query statements. What do you mean? If we use select * from myTable, all columns will be displayed. If we use SELECT FIELD1, Field2 from MyTable, only two columns are displayed. So, in the DataGrid, choose the column you want to display, the simplest method is not to modify the properties, but is done by modifying the SQL query statement.

There is also a small problem, that is, when we design the database, the name of the field is often in English. However, we have to use Chinese in DataGrid, we need to give each field alias in the SELECT statement. For example: Select Name As Name, CardID AS INGA from MyTable.

Sometimes, we are not convenient to use this way to choose the columns we want to display, then we use the property generator to set it.

In the design view, select the DataGrid, then "Property Window" will have a link to the "Properties Builder", click this link (or find the columns attribute), pop up a dialog box, we can pass this dialog To set the columns to choose:

First, we remove the hook in front of the "automatically created in runtime", which is no longer automatically created, and only the column you bind.

Click "Column" on the left, and the "Bind Column" "button column", etc., here we have to choose "Bind Column". Add a binding column, then fill in the "Header Text" and other items. The header text refers to the page title, "Data Field" fills in the name of the field you want to display. Then, you have to bind a few fields, choose a few bindings.

2, modify the style of DataGrid

The table of DataGrid draws by default is difficult, so I need to customize it. Checking the DataGrid, the bottom of the Properties window will appear link, click this link, you will pop up a dialog that allows you to select the format, select the format you wish.

I don't know how you think, anyway, I think there are two formats in this format, and it is also in line with the company's design specification, so I tend to use these formats. If you are still not satisfied, then you need to customize yourself. It is also very simple to customize yourself, that is, you can modify the properties of the "Style" class. In addition, you can also complete the modification of the style properties through the property generator. For example, you don't want your form back, then you go to the property generator, select "Format", then select "Item on the right, put the" unit grid text in each sub-text " The hook is OK.

转载请注明原文地址:https://www.9cbs.com/read-94074.html

New Post(0)