Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I have a datagrid and add the columns dynamically like this,
VB
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()




VB
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
           'Add the column to the DataColumnrow_tuple.
           dt.Columns.Add(dtcol)
       Catch ex As Exception
           ''MsgBox(ex.ToString)
       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..
Posted
Updated 3-Dec-12 2:58am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900