Add record serial numbers (repost) for the datagridview in VB.net)

Source: Internet
Author: User

 

Add record serial numbers (repost) for the datagridview in VB.net)

In database processing, it is often used to search databases and display query results using the datagridview, but the current number cannot be displayed in the first column.

Generally, for a large amount of data (not greater than 1000), we do not need to add sequence numbers. For a small amount of data (less than 1000), we can define the following process for numbering:

Sub addnum (byval rn as integer)

Dim I as integer
For I = 1 to rn-1
Maid (I-1). cells (0). value = I
Next
Datagridview1.refresh ()
End sub

In the code, RN is the number of rows in the datagridview;

Right-click the datagridview control and select Edit column to add an unbound column header. For example, you can name it "sequence number ";

Cell (0) in datagridview1.rows (I-1). cells (0). value indicates the first column. My sequence is in the 1st column, so it is 0. If it is in the 3rd column, it is 2;

In this way, after the query is completed, the addnum process can be called to add sequence numbers, for example, addnum (datagridview1.rowcount ).

 

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.