Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET WinForm
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 22:56pm
Edited 3-Dec-12 3:58am
v4

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

  Print Answers RSS
0 OriginalGriff 475
1 Maciej Los 339
2 Richard MacCutchan 225
3 BillWoodruff 219
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
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