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

  • SEARCH
  • Home
  • 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 3936260
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:55:33+00:00 2026-05-19T23:55:33+00:00

I have a DataGridView that I am binding to a POCO. I have the

  • 0

I have a DataGridView that I am binding to a POCO. I have the databinding working fine. However, I have added a combobox column that I want to be different for each row. Specifically, I have a grid of purchased items, some of which have sizes (like Adult XL, Adult L) and other items are not sized (like Car Magnet.)

So essentially what I want to change is the DATA SOURCE for a combobox column in the data grid. Can that be done?

What event can I hook into that would allow me to change properties of certain columns FOR EACH ROW? An acceptable alternative is to change a property when the user clicks or tabs into the row. What event is that?

Seth

EDIT
I need more help with this question. With Triduses help I am SO close but I need a bit more information.

First, per the question, is the CellFormatting event really the best/only event for changing the DataSource for a combo box column. I ask because I am doing something rather resource/data intensive, not merely formatting the cell.

Second, the cellformatting event is being called just by having the mouse hover over the cell. I tried to set the FormattingApplied property inside my if-block and then I check for it in the if- test but that is returning a weird error message. My ideal situation is that I would apply change the data source for the combo box once for each row and then be done with it.

Finally, in order to set the data source of the combobox colunm I have to be able to cast the Cell inside my if block to a type of DataGridViewComboBoxColumn so that I can fill it with rows or set the datasource or something. Here is the code I have right now.

Private Sub ProductsDataGrid_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles ProductsDataGrid.CellFormatting

    If e.ColumnIndex = ProductsDataGrid.Columns("SizeDGColumn").Index Then ' AndAlso Not e.FormattingApplied Then
        Dim product As LeagueOrderProductInfo = DirectCast(ProductsDataGrid.Rows(e.RowIndex).DataBoundItem, LeagueOrderProductInfo)
        Dim sizes As LeagueOrderProductSizeList = product.ProductSizes
        sizes.RemoveSizeFromList(_parentOrderDetail.SizeID)

        'WHAT DO I DO HERE TO FILL THE COMBOBOX COLUMN WITH THE sizes collection.

    End If

End Sub

Please help. I am completely stuck and this task item should have taken an hour and I am 4+ hours in now. BTW, I am also open to resolving this by taking a completely different direction with it (as long as I can be done quickly.)

Seth

  • 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. Editorial Team
    Editorial Team
    2026-05-19T23:55:34+00:00Added an answer on May 19, 2026 at 11:55 pm

    I didn’t go the way of catching an event to change displayed values in a combobox for each row…Take a look at this approach (example), it’s very straightforward and easy to implement and does exactly what you want imho.:

    1. Declare an Item class with two simple properties (Name, Type)

    2. Create a DataGridView with two columns (one for Name, and the second for Type with ColumnType = DataGridViewComboBoxColumn and dataPropertyName = Type)

    3. “Attach” your (I assume) list of poco’s to the DataGridView

    4. And afterwards loop one-time only through your collection of rows; grab the DataGridViewComboBoxColumn for that row; Change it’s items property based upon the criteria that you have for the poco in that row.

    I leave it up to you to grab the poco for a specific row, or alternatively read some properties from hard-coded columns in the row…

    Here’s some sample code:

    namespace DataGridViewCustomComboboxItemsPerRow
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                List<int> types = new List<int>();
                List<Item> items = new List<Item>();
                Item item;
                for (int i = 0; i < 100; i++)
                {
                    item = new Item();
                    item.Name = "Item" + i.ToString();
                    item.Type = i;
    
                    items.Add(item);
                    types.Add(i);
                }
    
                //typeDataGridViewComboBoxColumn.DataSource = types;
                itemBindingSource.DataSource = items;
            }
    
            private void Form1_Shown(object sender, EventArgs e)
            {
                DataGridViewComboBoxCell dgvc;
    
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    dgvc = (DataGridViewComboBoxCell)dataGridView1.Rows[i].Cells[1];
    
                    // Your CUSTOM code here, I just did some stupid thing here...
                    dgvc.Items.Add(i - 1);
                    dgvc.Items.Add(i);
                    dgvc.Items.Add(i + 1);
                }
            }
        }
    
        public class Item
        {
            private string _name;
            private int _type;
    
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
    
            public int Type
            {
                get { return _type; }
                set { _type = value; }
            }
        }
    }
    

    The code is in C# but is pretty basic, so I guess it won’t cause problems in VB.NET. And this code really makes a one time loop (O(n)) to configure your combo’s for different rows and than it’s done.

    Hope this helps. Joep.

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

Sidebar

Related Questions

I've got some Columns in a DataGridView that have their Binding property set to
I have a DataGridView that I want to query using Linq (C# WinForm). I
I have a DataGridView that is bound to a DataTable, it has a column
I have a DataGridView in my form and I am binding that DataGridView to
I have a problem with my datagridview that is binding to an access table(access
I have a DataGridView that I'm binding to a DataTable. The DataTable is a
I have a DataGridView that uses databinding, with manually created columns, and this works
I am binding an array to a DataGridView. I have a column containing file
So I have this datagridview that is linked to a Binding source that is
I have a List that I want to bind to a DataGridView in a

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.