DataGrid With Combo VB .NET Program



Description:
           
             The Combo box is added in the data grid column. We will see how display and save data from a database. It will also show how we can add Combo Box, Text and other columns types to the Data Grid.


Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Text
Imports System.Xml
Public Class gridcombo
   
    Private cmbfunctionarea As System.Windows.Forms.ComboBox
    Private dtblfunctionalarea As DataTable
    Private dgdfunctionarea As DataGrid
    PopulateGrid()

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
End Class
frmInitialShortListing()
InitializeComponent()
PopulateGrid()
Private Sub PopulateGrid()
    Dim dtcol As DataColumn = Nothing
    Dim arrstrfunctionalarea As String() = Nothing
    Dim cmbfunctionarea As System.Windows.Forms.ComboBox
    Dim dtblfunctionalarea As DataTable
    cmbfunctionarea = New ComboBox
    cmbfunctionarea.Cursor = System.Windows.Forms.Cursors.Arrow
    cmbfunctionarea.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
    cmbfunctionarea.Dock = DockStyle.Fill
    cmbfunctionarea.SelectionChangeCommitted += New EventHandlercmbfunctionarea_SelectedIndexChanged
    arrstrfunctionalarea = New String(3) {}
    arrstrfunctionalarea(0) = "Functional Area"
    arrstrfunctionalarea(1) = "Min"
    arrstrfunctionalarea(2) = "Max"
    dtblfunctionalarea = New DataTable("Functionlarea")
    Dim i As Integer
    For i = 0 To 2
        Dim str As String = arrstrfunctionalarea(i)
        dtcol = New DataColumn(str)
        dtcol.DataType = System.Type.GetType("System.String")
        dtcol.DefaultValue = ""
        dtblfunctionalarea.Columns.Add(dtcol)
    Next i
    dgdfunctionarea.DataSource = dtblfunctionalarea
    If Not dgdfunctionarea.TableStyles.Contains("Functionarea") Then
        Dim dgdtblStyle As New DataGridTableStyle
        dgdtblStyle.MappingName = dtblfunctionalarea.TableName
        dgdfunctionarea.TableStyles.Add(dgdtblStyle)
        dgdtblStyle.RowHeaderVisible = False
        dgdtblStyle.HeaderBackColor = Color.LightSteelBlue
        dgdtblStyle.AllowSorting = False
        dgdtblStyle.HeaderBackColor=Color.FromArgb(8,36,107)dgtblStyle.RowHeaderVisible=False
        dgdtblStyle.HeaderForeColor = Color.White
        dgdtblStyle.HeaderFont = New System.Drawing.Font("Microsoft Sans")
        ",9F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,"(CType(0,System.Byte))
        dgdtblStyle.GridLineColor = Color.DarkGray
        dgdtblStyle.PreferredRowHeight = 22
        dgdfunctionarea.BackgroundColor = Color.White
        Dim colStyle As GridColumnStylesCollection
        colStyle = dgdfunctionarea.TableStyles(0).GriColumnStyles
        colStyle(0).Width = 100
        colStyle(1).Width = 50
        colStyle(2).Width = 50
        colStyle(3).Width = 80
    End If
    Dim dgtb As DataGridTextBoxColumn = CType(dgdfunctionarea.TableStyles(0).GridColumnStyles(0), DataGridTextBoxColumn)
End Sub

OUTPUT


Contact:
Mr. Roshan P. Helonde
Mobile: +91-7276355704
WhatsApp: +91-7276355704

Email: roshanphelonde@rediffmail.com
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *