Beginner's Guide: usage and problems of the DataGridView (1 ).

Source: Internet
Author: User

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.

 

Related Article

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.