Hi guys, I have a datagrid and add the columns dynamically like this,
create_column(pTable, "LeaveType", "string", False, "LeaveType", True, True, 50)
create_column(pTable, "TotalLeaves", "double", False, "TotalLeaves", False, False, 50)
create_column(pTable, "Year", "string", False, "Year", False, False, 50)
'Add Empty values to the table
con = GetCon()
con.Open()
Dim qry As String = " SELECT LEAVETYPE FROM LEAVETYPE"
Dim cmd As SqlCommand = New SqlCommand(qry, con)
dr = cmd.ExecuteReader
Dim nr As DataRow
While dr.Read
nr = pTable.NewRow
nr.Item(0) = dr(0)
nr.Item(1) = "0"
nr.Item(2) = ""
pTable.Rows.Add(nr)
End While
dGridView.DataSource = pTable
dr.Close()
con.Close()
Public Sub create_column(ByVal dt As DataTable, ByVal col_name As String, ByVal col_type As String, ByVal autoincr As Boolean, ByVal caption As String, ByVal read_property As Boolean, ByVal unique As Boolean, ByVal length As Integer)
Try
Dim dtcol As New DataColumn
If col_type.CompareTo("string") = 0 Then
dtcol.DataType = System.Type.GetType("System.String")
dtcol.MaxLength = length
ElseIf col_type.CompareTo("double") = 0 Then
dtcol.DataType = System.Type.GetType("System.Double")
ElseIf col_type.CompareTo("integer") = 0 Then
dtcol.DataType = System.Type.GetType("System.Int32")
End If
dtcol.ColumnName = col_name
dtcol.AutoIncrement = autoincr
dtcol.Caption = caption
dtcol.ReadOnly = read_property
dtcol.Unique = unique
dt.Columns.Add(dtcol)
Catch ex As Exception
End Try
only total leaves column should allow decimal or numbers in datagrid. By default total leaves column of rows zero's.
initially :
by default.
totalleaves
0
0
0
i need only adding the decimals numbers .
Please any one help me..