Beginner's Guide: usage and problems of the DataGridView (1 ).
I am doing WinForm development. For WinForm development, the DataGridview control is no longer familiar. The usage frequency is extremely high.
When I was just developing WinForm, I encountered a lot of trouble because I was not familiar with this control. Now I feel that I have mastered it. I will list some common usage and problems for reference by new beginners.
1. the attribute setting before the data is bound to the DataGridview is minor.
(1) If the structure of the table to be displayed is specified in advance, right-click the table and choose edit column to enter the member displayed on the editing control page.
It can be seen that, without specially modifying some attributes, the page generated by the Datagridview datagricontains a blank column and a blank row, and each grid can be clicked and modified.
In my personal opinion, the basic problem is to set the Datagridview to remove the blank columns in the blank row and select a row for each click instead of a column.
To achieve this goal, we need to set:
Control property: AllowUserToAddRows = false; // remove the last blank row.
Control property: RowHeadersVisible = false; // remove the empty column in the first column.
Control property: SelectionMode = FullRowSelect; // select the entire row in each selection.
Edit column attributes: ReadOnly = true; make a column read-only (generally, it is recommended that you set the column read-only when creating a column in the displayed Datagridview. You can also set the read-only attribute = true when traversing each column in the code or directly set the Datagridview control attribute ReadOnly = true)
Effect:
You can see that the column title is clickable and can be used for sorting. The arrows indicate the order or reverse order.
I personally think this is a very convenient function, but it does not rule out the need to make the column title unclickable.
Which of the following settings is required: edit the control column-> SortMode = NotSortTable
Therefore, this column cannot be clicked for sorting.
This is a small problem before binding data. The new hand. The next section describes the data source binding problem of the Datagridview.