© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
Quick Links
Easy Studies

  HomeSource Code DotNet ►VB.Net▼

DataGrid With Combo



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



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


    End Sub

End Class




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 = ""


    Next i

    dgdfunctionarea.DataSource = dtblfunctionalarea

    If Not dgdfunctionarea.TableStyles.Contains("Functionarea") Then

        Dim dgdtblStyle As New DataGridTableStyle

        dgdtblStyle.MappingName = dtblfunctionalarea.TableName


        dgdtblStyle.RowHeaderVisible = False

        dgdtblStyle.HeaderBackColor = Color.LightSteelBlue

        dgdtblStyle.AllowSorting = False


        dgdtblStyle.HeaderForeColor = Color.White

        dgdtblStyle.HeaderFont = New System.Drawing.Font("Microsoft Sans")


        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



SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑