[NET. VB] Small problem collection (for beginners reference)
Source: Internet
Author: User
Reference | beginners | Question statement:
1, all the code does not indicate the source of all for I write
2, all the code in the debugging through the machine
3, this paste applies to beginners (I also)
4, welcome Fellow treatise, provide ideas or code
5, I strive to supplement the daily content
6, not my consent, do not reprint the code I wrote
7. Do you want 6th above?
8, HA, the statement is written like this, is not serious, nor normative
Water as smoke 2004.7.19
[Control class]
Treeview
1, add a ToolTip to the node (2004.7.19)
Private Tmptreenode as TreeNode
Private Mtreeviewtooltip as New ToolTip
Private Sub Treeview1_mousemove (ByVal sender as Object, ByVal e as System.Windows.Forms.MouseEventArgs) Handles TreeView1 . MouseMove
Dim Mnode as TreeNode
Mnode = Me.TreeView1.GetNodeAt (e.x, e.y)
' No node currently
If Mnode is nothing Then
Mtreeviewtooltip.settooltip (Me.treeview1, nothing)
Exit Sub
End If
' More than the current node's bounds
If MNode.Bounds.Right < e.x OrElse mNode.Bounds.Left > E.x Then
Mtreeviewtooltip.settooltip (Me.treeview1, nothing)
Exit Sub
End If
' The same node
If Mnode is Tmptreenode Then
Exit Sub
End If
Mtreeviewtooltip.automaticdelay = 500
Mtreeviewtooltip.settooltip (Me.treeview1, Mnode.text)
Tmptreenode = Mnode
End Sub
Datagrid
1, the length of the Adaptive column (2004.7.19)
' Define a field information class
Private Class Columninfo
public [Name] as String
public [DataType] as String
Public maxwidth as Integer = 0
Public Sub comparestringlength (ByVal mstring as String)
Dim Mlength as Integer
Mlength = System.Text.Encoding.Default.GetBytes (mstring). Length ()
If MaxWidth < mlength Then MaxWidth = mlength
End Sub
Public Function ColumnWidth (ByVal Mdatagrid as DataGrid) as Integer
Dim mgraphics as Graphics = Mdatagrid.creategraphics
Dim Mcolwidth as Single
Mcolwidth = mgraphics.measurestring (New String (CType ("A", Char), maxwidth), Mdatagrid.font). Width + 2
Return CType (Mcolwidth, Integer)
End Function
End Class
Private Sub makedatagridautoextend (ByVal Mdatagrid as DataGrid)
' Judge Mdatagrid data source Type
' Exit if the binding is a dataset or DataViewManager or no data source is bound
If TypeOf Mdatagrid.datasource is System.Data.DataSet OrElse _
TypeOf Mdatagrid.datasource is System.Data.DataViewManager OrElse _
Mdatagrid.datasource is nothing Then Exit Sub
' Consider two kinds of data sources, one is DataView, the other is DataTable
Dim DT as DataTable
If TypeOf Mdatagrid.datasource is System.Data.DataView Then
DT = CType (Mdatagrid.datasource, DataView). Table
Else
DT = CType (Mdatagrid.datasource, DataTable)
End If
' Take each field information
Dim mcolumninfo (dt. COLUMNS.COUNT-1) as Columninfo
Dim i as Integer = 0
Dim Mcolumn as DataColumn
For each mcolumn in dt. Columns
Dim MInfo as New columninfo
With MInfo
. Name = Mcolumn.columnname
. DataType = mColumn.DataType.ToString
. Comparestringlength (Mcolumn.columnname)
End With
Mcolumninfo (i) = MInfo
i + 1
Next
' Take the maximum length of each field
Dim Mrow as DataRow
For each mrow in dt. Rows
For i = 0 to dt. Columns.count-1
If not IsDBNull (Mrow (i)) Then
Mcolumninfo (i). Comparestringlength (CType (Mrow (i), String)
End If
Next
Next
' Build DataGridTableStyle
Dim ts as New DataGridTableStyle
Ts. MappingName = dt. TableName
For i = 0 to dt. Columns.count-1
If Mcolumninfo (i). Datatype.equals ("System.Boolean") Then
' This is a Boolean field
Dim Blncol as New datagridboolcolumn
With Blncol
. MappingName = Mcolumninfo (i). Name
. HeaderText = Mcolumninfo (i). Name
. Width = Mcolumninfo (i). ColumnWidth (Mdatagrid)
. Nulltext = ""
End With
Ts. Gridcolumnstyles.add (Blncol)
Else
' Non-boolean field
Dim Txtcol as New datagridtextboxcolumn
With Txtcol
. MappingName = Mcolumninfo (i). Name
. HeaderText = Mcolumninfo (i). Name
. Width = Mcolumninfo (i). ColumnWidth (Mdatagrid)
. Nulltext = ""
. ReadOnly = False ' This can be set to read-only
. format = "'" ' Here you can set the display format to show the day and the seconds are set here.
End With
Ts. Gridcolumnstyles.add (Txtcol)
End If
Next
MDataGrid.TableStyles.Clear ()
MDATAGRID.TABLESTYLES.ADD (TS)
' As for other functions, such as binding events, the following supplements
End Sub
' Call
Private Sub button2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button2.click
Makedatagridautoextend (ME.DATAGRID1)
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