[Original] IRD

Source: Internet
Author: User

Many beginners of VB. NET are almost all worried about the failure to implement many small functions,
The following is a comprehensive general code for beginners to study the many problems I encountered in the Forum:

'General-style regionird
'Power by: landlordh
'Call:
Change 'strheaders () to the column name you need.
'Iwidths () is changed to the corresponding column width.
'Inputnum is assigned a value before styling.
'Style (maid, dataset1.tables ("tabname "))
'
'================================================ ======================================

'Column name, corresponding field name
Public strheaders () as string = {"no.", "time", "topic", "content "}
'Column width, 0 hidden (Priority lower than inputnum), corresponding column width
Public iwidths () as integer = {0, 70,130, 0}
'Display several columns. If it is null, all columns are displayed. If it is 0, all columns are hidden.
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
'Process parameters in 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 characters you entered do 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
'Processing click rows
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 = column number-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 ("An error occurred while formatting the grid ")
End try
End sub

Public sub textboxenterhandler (byval sender as object, byval e as system. eventargs)
Dim inner as control = sender
Inner. Visible = false
If maid> = 0 then
Datagrid1.select (maid)
End if
End sub

End

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.