Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 64503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:48:00+00:00 2026-05-10T18:48:00+00:00

How do you access the items collection of a combo box in a specific

  • 0

How do you access the items collection of a combo box in a specific row in a DataGridView?

I’m populating the combo as follows:

          Dim VATCombo As New DataGridViewComboBoxColumn             With VATCombo                 .HeaderText = 'VAT Rate'                 .Name = .HeaderText                 Dim VATCol As New JCVATRateCollection                  VATCol.LoadAll(EntitySpaces.Interfaces.esSqlAccessType.StoredProcedure)                 For Each Rate As JCVATRate In VATCol                     .Items.Add(Rate.str.VATRate)                 Next                 .Sorted = True                  VATCol = Nothing                  .ToolTipText = 'Select VAT Rate'                 .AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells                 .CellTemplate.Style.BackColor = Color.Honeydew                 .DisplayIndex = 8                 .AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill              End With             .Columns.Add(VATCombo)             VATCombo = Nothing 

I want to be able to set a default value for each new line added to the grid, I also want to be able to change the values in the combo based on other business logic. I realise I can just set the cell value directly but I want to avoid hard-coding the values into the system and rely on the database to populate.

I’m sure it must be straight-forward but it’s eluding me…..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:48:01+00:00Added an answer on May 10, 2026 at 6:48 pm

    The problem with the basic combobox in EditGridView is that all rows share the same combobox, so you cannot change it.

    You to create a new class (ComboEditingControl) inherited from the ComboBox and implementing IDataGridViewEditingControl:

    (e.g. customdropdown.vb:)

    Imports System.Collections.Generic Imports System.Drawing Imports System.Windows.Forms  Friend Class ComboEditingControl Inherits ComboBox Implements IDataGridViewEditingControl  Private dataGridViewControl As DataGridView Private valueIsChanged As Boolean = False Private rowIndexNum As Integer Private ItemSelected As String  Public Sub New()     Me.DropDownStyle = ComboBoxStyle.DropDownList End Sub   Public Property EditingControlFormattedValue() As Object _     Implements IDataGridViewEditingControl.EditingControlFormattedValue      Get         Return ItemSelected     End Get      Set(ByVal value As Object)         If TypeOf value Is Decimal Then             Me.SelectedItem = value.ToString()         End If     End Set End Property   Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object _     Implements IDataGridViewEditingControl.GetEditingControlFormattedValue     Return ItemSelected End Function  Public ReadOnly Property EditingControlCursor() As Cursor _     Implements IDataGridViewEditingControl.EditingPanelCursor     Get         Return MyBase.Cursor     End Get End Property  Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) _     Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl      Me.Font = dataGridViewCellStyle.Font     Me.ForeColor = dataGridViewCellStyle.ForeColor     Me.BackColor = dataGridViewCellStyle.BackColor  End Sub  Public Property EditingControlRowIndex() As Integer _     Implements IDataGridViewEditingControl.EditingControlRowIndex      Get         Return rowIndexNum     End Get     Set(ByVal value As Integer)         rowIndexNum = value     End Set  End Property  Public Function EditingControlWantsInputKey(ByVal key As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean _     Implements IDataGridViewEditingControl.EditingControlWantsInputKey      ' Let the DateTimePicker handle the keys listed.     Select Case key And Keys.KeyCode         Case Keys.Up, Keys.Down, Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp             Return True         Case Else             Return False     End Select End Function  Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _     Implements IDataGridViewEditingControl.PrepareEditingControlForEdit     ' No preparation needs to be done. End Sub  Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements _     IDataGridViewEditingControl.RepositionEditingControlOnValueChange     Get         Return False     End Get End Property  Public Property EditingControlDataGridView() As DataGridView _     Implements IDataGridViewEditingControl.EditingControlDataGridView      Get         Return dataGridViewControl     End Get     Set(ByVal value As DataGridView)         dataGridViewControl = value     End Set  End Property  Public Property EditingControlValueChanged() As Boolean _     Implements IDataGridViewEditingControl.EditingControlValueChanged      Get         Return valueIsChanged     End Get     Set(ByVal value As Boolean)         valueIsChanged = value     End Set End Property   ''' <summary> ''' Notify the DataGridView that the contents of the cell have changed. ''' </summary> ''' <param name='eventargs'></param> ''' <remarks></remarks> Protected Overrides Sub OnSelectedIndexChanged(ByVal eventargs As EventArgs)     valueIsChanged = True     dataGridViewControl.NotifyCurrentCellDirty(True)     MyBase.OnSelectedItemChanged(eventargs)     ItemSelected = SelectedItem.ToString() End Sub End Class 

    2 more classes, note in the InitializeEditingControl you need to build the items for the specific rows that you are on

    Friend Class ComboColumn     Inherits DataGridViewColumn      Public Sub New()         MyBase.New(New ComboCell())     End Sub      Public Overrides Property CellTemplate() As DataGridViewCell         Get             Return MyBase.CellTemplate         End Get         Set(ByVal value As DataGridViewCell)             ' Ensure that the cell used for the template is a ComboCell.             If Not (value Is Nothing) AndAlso Not value.GetType().IsAssignableFrom(GetType(ComboCell)) Then                 Throw New InvalidCastException('Must be a ComboCell')             End If             MyBase.CellTemplate = value         End Set     End Property End Class  Friend Class ComboCell     Inherits DataGridViewTextBoxCell      Public Sub New()     End Sub      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)          Dim GetValueFromRowToUseForBuildingCombo As String = Me.DataGridView.Rows(rowIndex).Cells(0).Value.ToString()          ctl.Items.Clear()         For Each thing As String In ACollection             ctl.Items.Add(Sheet)         Next           If Me.Value Is Nothing Then             ctl.SelectedIndex = -1         Else             ctl.SelectedItem = Me.Value         End If     End Sub      Public Overrides ReadOnly Property EditType() As Type         Get             Return GetType(ComboEditingControl)         End Get     End Property      Public Overrides ReadOnly Property ValueType() As Type         Get             Return GetType(String)         End Get     End Property      Public Overrides ReadOnly Property FormattedValueType() As System.Type         Get             Return GetType(String)         End Get     End Property      Public Overrides ReadOnly Property DefaultNewRowValue() As Object         Get             Return ''         End Get     End Property End Class 

    finally in the OnLoad code of your form, programatically add the control to the Grid:

    Dim c As New ComboColumn c.HeaderText = 'Sheet' c.DataPropertyName = 'My Combo' c.ToolTipText = 'Select something from my combo' MyDataGridView.Columns.Add(c) 

    To Get & Set just use the ThisRow.Cells(ComboCol).Value

    The first field is generic, the other inherit and have the custom code for each DataGridView that you need

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 241k
  • Answers 241k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you have a regular 2D array of chars you… May 13, 2026 at 7:19 am
  • Editorial Team
    Editorial Team added an answer sorry guys. i returned to many uneccassary (difficult word to… May 13, 2026 at 7:19 am
  • Editorial Team
    Editorial Team added an answer Try the following. It has to do with Application Pool… May 13, 2026 at 7:19 am

Related Questions

I have a combo box on a WinForms app in which an item may
I have always thought it was best practice to be explicit in naming my
Imagine an object you are working with has a collection of other objects associated
I need to iterate through a LinkedList<T> (in .NET 2.0) and remove all the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.