Many beginners vb.net, almost all of the small work can be realized and distressed,
The following I personally encountered many problems in the forum of the synthesis of general code, for beginners to study:
' Common style Datagird
' Power By:landlordh
Call
' Strheaders () changed to the name of the column
' Iwidths () change to the corresponding column width
' Inputnum Assignment before styling
' Style (DATAGRID1, Dataset1.tables ("TabName"))
'
'=================================================================
' Column name, field corresponding name
Public strheaders () as String = {"Number", "Time", "subject", "content"}
' column width, 0 hidden (priority lower than inputnum), corresponding column width
Public iwidths () as Integer = {0, 70, 130, 0}
' Show a few columns, empty to show all, 0 to hide all
Public Inputnum as String
Public Sub style (ByVal datagridname as DataGrid, ByVal Dataname as DataTable)
Try
Datagridname. DataSource = Dataname
' Show new
' Dataname. Defaultview.allownew = False
' Edit directly in the DataGrid
' Dataname. Defaultview.allowedit = False
Dim I as Integer
' Handle the parameters that show the first few columns
If Trim (inputnum) <> "" Then
Dim Num as Integer
Try
num = CInt (Trim (Inputnum))
Try
For i = 0 to Iwidths.length-1
If I >= inputnum Then
Iwidths (i) = 0
End If
Next
Catch ex as Exception
End Try
Catch ex as Exception
MsgBox ("The character you entered does not meet the requirements")
End Try
End If
Dim ts as New DataGridTableStyle
Ts. MappingName = Dataname. TableName
Ts. AlternatingBackColor = System.Drawing.Color.PapayaWhip
Ts. BackColor = System.Drawing.Color.WhiteSmoke
Ts. SelectionBackColor = System.Drawing.Color.LightSteelBlue
Ts. Selectionforecolor = Color.Black
Ts. Rowheaderwidth = 10
Ts. Preferredrowheight = 20
For i = 0 to Dataname. Columns.count-1
Dim AC as New datagridtextboxcolumn
' Process Click line '
' AddHandler AC. Textbox.enter, AddressOf Textboxenterhandler
Ac. HeaderText = Strheaders (i)
Ac. MappingName = Dataname. Columns (i). ColumnName
Ac. Textbox.width = Iwidths (i)
Ts. Preferredcolumnwidth = AC. Textbox.width
' Which column, i= number of columns-1
If i = 1 Then
Ac. Format = "Yyyy-mm-dd hh:mm:ss"
' AC. ReadOnly = True
' AC. Nulltext = ""
Ac. Alignment = HorizontalAlignment.Center
End If
If i = 1 Or i = 2 Then
' AC. ReadOnly = True
' AC. Nulltext = ""
Ac. Alignment = HorizontalAlignment.Center
End If
Ts. Gridcolumnstyles.add (AC)
Next
Datagridname. Tablestyles.clear ()
Datagridname. Tablestyles.add (TS)
Catch ex as Exception
MessageBox.Show ("Format grid error")
End Try
End Sub
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