Click here to Skip to main content
12,945,575 members (49,984 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
           '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 2-Dec-12 21:56pm
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,170
Maciej Los 2,443
Jochen Arndt 1,910
ppolymorphe 1,775


Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100