Click here to Skip to main content
12,898,174 members (69,134 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
hello friends,

i have some propblem in datagridviewcombobocolumn with custom datasource property in when i add datasource it does not populate in datagridview combobox column it giving nothing.. any one please help me out from this problem...

code comboboxcell:

Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle) ' Set the value of the editing control to the current cell value. MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
    Dim ctl As ComboEditingControl = CType(DataGridView.EditingControl, ComboEditingControl)
    ctl.DropDownStyle = ComboBoxStyle.DropDown
    ctl.AutoCompleteSource = AutoCompleteSource.ListItems
    ctl.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest

    If (Me.DataGridView.Rows(rowIndex).Cells(0).Value <> Nothing) Then
        Dim GetValueFromRowToUseForBuildingCombo As String = Me.DataGridView.Rows(rowIndex).Cells(0).Value.ToString()
        Dim dt As New DataTable()
            dt = TryCast(DirectCast(Me.DataGridView.Columns(ColumnIndex), ComboColumn).DataSource, DataTable)
        Catch ex As Exception
        End Try
        If (dt Is Nothing) Then

            Dim thing As DataRow
            For Each thing In dt.Rows
        End If

        If Me.Value Is Nothing Then
            ctl.SelectedIndex = -1
            ctl.SelectedItem = Me.Value
        End If
        ctl.EditingControlDataGridView = Me.DataGridView
    End If
End Sub

from code:

Dim widgets As New WidgetDataHandler
        Dim obj = widgets.GetAllWigetTypes()
        Dim dt As New DataTable
        Dim ListofmyObjects As New List(Of widget_types)(obj)
        Dim objList As New cObjectToTable(Of widget_types)(ListofmyObjects)

        dt = objList.GetTable()
        Dim obj1
        For Each obj1 In obj
        Dim col1 As New DataGridViewTextBoxColumn
        col1.DisplayIndex = 0
        col1.DataPropertyName = "Id"
        col1.HeaderText = "Id"

        Dim col2 As New ComboColumn
        col2.DisplayIndex = 1
        col2.SortMode = DataGridViewColumnSortMode.Automatic
        col2.HeaderText = "Name"
        col2.DataPropertyName = "Name"
        col2.ToolTipText = "Select something from my combo"
        Dim dst As New DataSet
        'Dim dt1 As New DataTable
        'For Each thing In dt.Rows
        '    MsgBox(thing(1).ToString)
        '    dt1.Rows.Add(thing(1).ToString)
        col2.DataSource = dst.Tables(0)
        col2.DisplayMember = "Name"
        dgvi00.DataSource = blPersons.BindingSource

        'setup the bindings for the binding navigator
        Dim bn As New _365_Media_Library.BindingNavigatorWithFilter
        bn.Dock = DockStyle.Bottom
        bn.GripStyle = ToolStripGripStyle.Hidden
        bn.BindingSource = blPersons.BindingSource

note :

its working good in standalone application

regards and thanks
Posted 18-Dec-12 18:06pm

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

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 19 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