Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
hello friends,
 
i have some propblem in datagridviewcombobocolumn with custom datasource property in vb.net. 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()
 
        ctl.Items.Clear()
 
        Dim dt As New DataTable()
        Try
            dt = TryCast(DirectCast(Me.DataGridView.Columns(ColumnIndex), ComboColumn).DataSource, DataTable)
        Catch ex As Exception
            MsgBox("error")
        End Try
 
        If (dt Is Nothing) Then
 

            ctl.Items.Add("")
        Else
            Dim thing As DataRow
            For Each thing In dt.Rows
                ctl.Items.Add(thing(0).ToString)
            Next
 
        End If
 

        If Me.Value Is Nothing Then
            ctl.SelectedIndex = -1
        Else
            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
            blPersons.Add(obj1)
        Next
 
       
        Dim col1 As New DataGridViewTextBoxColumn
        col1.DisplayIndex = 0
        col1.DataPropertyName = "Id"
        col1.HeaderText = "Id"
 
        dgvi00.Columns.Add(col1)
 

 
        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

        'dt1.Columns.Add(col2.HeaderText)
        'For Each thing In dt.Rows
        '    MsgBox(thing(1).ToString)
        '    dt1.Rows.Add(thing(1).ToString)
        'Next

        dst.Tables.Add(dt)
        col2.DataSource = dst.Tables(0)
        col2.DisplayMember = "Name"
        Me.dgvi00.Columns.AddRange(col2)
        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
        Me.Controls.Add(bn)
        bn.BindingSource = blPersons.BindingSource
 
note :
 
its working good in standalone application
 
regards and thanks
sarva
Posted 18-Dec-12 18:06pm
Sarrrva3.4K

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 271
1 OriginalGriff 223
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


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