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 716603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:19:04+00:00 2026-05-14T05:19:04+00:00

I’m trying to bind a table of structures to a DataGridView. Loading and viewing

  • 0

I’m trying to bind a table of structures to a DataGridView. Loading and viewing the table is working fine but I can’t edit a value and get it stored back into the table. Here’s what I’m doing.

I have a “primitive” data type, Real defined by

public struct MyReal:IMyPrimative
{
    public Double m_Real;
    //...
    public MyReal(String val)
    {
        m_Real = default(Double);
        Init(val); 
    }
    //...
}

It gets used in a structure:

public struct MyReal_Record : IMyRecord
{
    public MyReal Freq { get; set;}
    MyReal_Record(String[] vals)
    {
        Init(vals);
    }
}

And the structure is used to define a table using a generic Binding List

public class MyTable<S> : BindingList<S> where S: struct, IMyRecord
{
    public Type typeofS;
    public MyTable() 
    {
        typeofS = typeof(S);
        // ... 
    }

This table is used as a binding source for a grid, dynamically.

    private void miLoadFile_Click(object sender, EventArgs e)
    {
        MyModel.Table<Real_Record> RTable = new MyModel.Table<Real_Record>();
        //... Table initialized here

        //set up grid with virtual mode
        dataGridView1.DataSource = RTable;
    }

All of this works fine and I can create RTable, initialize it and display it in a grid. The grid allows editing and has events set for CellParsing and CellFormatting which look like:

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (e.DesiredType != typeof(String))
            return;
        e.Value = e.Value.ToString();
    }

    private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
    {
        if (e.DesiredType != typeof(MyReal))
            return;
        e.Value = new MyReal(e.Value.ToString());
        e.ParsingApplied = true;
        this.dataGridView1.UpdateCellValue(e.ColumnIndex, e.RowIndex);
    }

When I edit a value in a cell, I can change the text. On leaving the cell, CellParsing fires and the event handler is called. Everything seems to be correct going into the CellParsing handler. e.DesiredType is MyReal. e.Value is a string with the new value. After the new MyReal is created from the string, e.Value is set correctly. RowIndex and ColumnIndex are correct. ReadOnly is set false.

However, when I leave the cell, the system restores the original value to the cell. I thought the UpdateCellValue would replace the value in the dataSource but I seem to be missing something.

What did I miss?

Thanks,
Max

  • 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-14T05:19:05+00:00Added an answer on May 14, 2026 at 5:19 am

    I found the answer on another forum (social.msdn.microsoft.com) thanks to Aland Li.

    “When we bind a List of objects to a control, the objects in the list must be of reference type, not value type. In other words, Real_Record must defined as class.

    If Real_Record is of value type, a copy of the Real_Record item in the list is transferred to the DataGridView to initialize the binding. When the Real value is modified, the copy of the Real_Record is changed, but the old item in the list is not modified.”

    If anyone knows how to get around this limitation, I’d love to hear it.
    Max

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just add an user to your local users and groups… May 14, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer There is no Oracle built-in to do this sort of… May 14, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer xrandr prints the status of a screen ("connected", "disabled", "disconnected").… May 14, 2026 at 9:26 pm

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.