Hide and delete rows and columns of the DataGridView

Source: Internet
Author: User

1) Hide rows and columns

[VB. NET]
'Hide the first column of maid
DataGridView1.Columns (0). Visible = False
'Hide the first line of maid
DataGridView1.Rows (0). Visible = False


[C #]
// Hide the first column of DataGridView1
DataGridView1.Columns [0]. Visible = false;
// Hide the first row of DataGridView1
DataGridView1.Rows [0]. Visible = false;

2) Hide the row header and column header

[VB. NET]
'Column header hiding
Maid = False
'Line header hiding
Maid = False


[C #]
// Hide the column header
Maid = false;
// Hide the row Header
Maid = false;

3) Delete rows and columns

[VB. NET]
'Delete a column named "Column1"
DataGridView1.Columns. Remove ("Column1 ")
'Delete the first column
DataGridView1.Columns. RemoveAt (0)
'Delete the first line
DataGridView1.Rows. RemoveAt (0)


[C #]
'Delete a column named "Column1"
DataGridView1.Columns. Remove ("Column1 ");
'Delete the first column
DataGridView1.Columns. RemoveAt (0 );
'Delete the first line
DataGridView1.Rows. RemoveAt (0 );

4) Delete the selected row

[VB. NET]
For Each r As DataGridViewRow In DataGridView1.SelectedRows
If Not r. IsNewRow Then
DataGridView1.Rows. Remove (r)
End If
Next


[C #]
Foreach (DataGridViewRow r in DataGridView1.SelectedRows)
{
If (! R. IsNewRow)
{
DataGridView1.Rows. Remove (r );
}
}

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.