ที่มา:
หลังจาก Import ไฟล์ Excel เข้ามาแล้ว มีบางคอลัมน์ที่ไม่ต้องการข้อมูล จะมีชื่อขึ้นต้นด้วย NoName ซึ่งเราต้องการซ่อนคอลัมน์เหล่านี้ ดังรูปข้างล่างนี้
สามารถทำได้หลายวิธี
ลองทำดูแล้วได้ผลดี ขอแนะนำ 2 แบบ
แบบที่ 1
With DataGridView1
For Each column As DataColumn In YourDataTable.Columns
If Len(column.ColumnName) >= 6 Then
colName = Trim(column.ColumnName).Substring(0, 6)
If colName = "NoName" Then
.Columns(column.ColumnName).Visible = False
End If
End If
Next
End With
และแบบที่ 2
With DataGridView1
For i As Integer = 0 To YourDataTable.Columns.Count - 1
If Len(.Columns(i).HeaderText.Trim) >= 6 Then
colName = .Columns(i).HeaderText.Trim.Substring(0, 6)
If colName = "NoName" Then
.Columns(i).Visible = False
End If
End If
Next
End With

No comments:
Post a Comment