Home    
Log In    
Share Code    
Join    

Navigation
 Skip Navigation Links.

Forums
Skip Navigation Links.

Search

 

Advertisement
 
VB.NET Source Code > Add Combo to Datagird Source Code
Details
Author: ptaylor
Views: 1184

Add Combo to Datagird
Description
Programmatically add a combo to a Datagird

In this example the database has a column called "StartDay" set as an Int32
 
 
Code:
Dim ColumnDays As New DataGridViewComboBoxColumn
Dim tblDays As New DataTable
Dim DayRow As DataRow


   tblDays.Columns.Add("ID")   'Day as int column
   tblDays.Columns.Add("Day")   'Day as String column

   For Day As DayOfWeek = 0 To 6   'For each day
      DayRow = tblDays.NewRow   'Create a new row
      DayRow("ID") = CType(Day, System.Int32)   'Add the day number
      DayRow("Day") = Day.ToString   'Add the day string
      tblDays.Rows.Add(DayRow)   'Add the row to a table
   Next

   ColumnDays.HeaderText = "Start Day"   'Display test on header
   ColumnDays.DataSource = tblDays   'The day table
   ColumnDays.DisplayMember = "Day"   'The day as string
   ColumnDays.ValueMember = "ID"   'The day as int
   ColumnDays.DataPropertyName = "StartDay" 'The data column from the database

   dgData.Columns("StartDay").Visible = False   'Hide the Original column
   dgData.Columns.Add(ColumnDays)      'Add the combo column to the DateGrid

Date Added: 17/04/2008 13:20:27





Comments


If you log in you can add a comment of your own!
 
 
Welcome Guest
 
  Log In Name
 
  Password
 
 
Statistics
Your Details: Not Logged In
  Join Date: N/A
  Last Logon: N/A
  Code Snippets: N/A
  Code Comments: N/A
  Forum Posts: N/A
  Forum Subjects: N/A

Site Wide
  Code Snippets: 32
  Code Comments: 2
  Forum Posts: 52
  Forum Subjects: 24
 
Random Code
Bind SQL Data to datagrid
Use this to bind SQL Data to the datagrid

Language: VB6

 
Advertisement


All the Source Code and Tutorials on this site are free for you to use as you require.