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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:43:42+00:00 2026-06-11T12:43:42+00:00

In my DataGridView, I am assigning my values to cells like this: for (int

  • 0

In my DataGridView, I am assigning my values to cells like this:

for (int i = 0; i < count; i++)
{
    int j = i + 1;
    DGVPointCtrl.Rows.Add(new DataGridViewRow());

    DGVPointCtrl.Rows[j].Cells["pointidentifier"].Value = pointCommonInfo[i].pointidentifier;
    DGVPointCtrl.Rows[j].Cells["pointname"].Value = pointCommonInfo[i].pointname;
    DGVPointCtrl.Rows[j].Cells["backup"].Value = pointCommonInfo[i].backup;
    DGVPointCtrl.Rows[j].Cells["covenable"].Value = pointCommonInfo[i].covenable;
    DGVPointCtrl.Rows[j].Cells["covlifetime"].Value = pointCommonInfo[i].covlifetime;
    DGVPointCtrl.Rows[j].Cells["covtarget"].Value = pointCommonInfo[i].covtarget;
    DGVPointCtrl.Rows[j].Cells["description"].Value = pointCommonInfo[i].description;
    DGVPointCtrl.Rows[j].Cells["historyenable"].Value = pointCommonInfo[i].historyenable;
    DGVPointCtrl.Rows[j].Cells["pointaddress"].Value = pointCommonInfo[i].pointaddress;
    DGVPointCtrl.Rows[j].Cells["pointtype"].Value = pointCommonInfo[i].pointtype;
    DGVPointCtrl.Rows[j].Cells["activetext"].Value = pointSpecificInfo[i].activetext;
    DGVPointCtrl.Rows[j].Cells["alarmenable"].Value = pointSpecificInfo[i].alarmenable;

    DGVPointCtrl.Rows[i].Cells["alarmenablehigh"].Value = pointSpecificInfo[i].alarmenablehigh;
    DGVPointCtrl.Rows[i].Cells["alarmenablelow"].Value = pointSpecificInfo[i].alarmenablelow;
    DGVPointCtrl.Rows[j].Cells["alarmvalue"].Value = pointSpecificInfo[i].alarmvalue;
    DGVPointCtrl.Rows[j].Cells["correctvalue"].Value = pointSpecificInfo[i].correctvalue;
    DGVPointCtrl.Rows[j].Cells["covincrement"].Value = pointSpecificInfo[i].covincrement;
    ...

Pretty dirty stuff. The cell names match the properties of my List of pointCommonInfo and pointSpecificInfo, so I decided to do use reflection:

for (int i = 0; i < count; i++)
{
    int j = i + 1;
    DGVPointCtrl.Rows.Add(new DataGridViewRow());
    FieldInfo[] fieldCommon = typeof(PointCommonInformation).GetFields();
    FieldInfo[] fieldSpecific = typeof(PointSpecificInformation).GetFields();
    foreach (FieldInfo field in fieldCommon)
    {
        DGVPointCtrl.Rows[j].Cells[field.Name].Value = //?
    }

    foreach (FieldInfo field in fieldSpecific)
    {
        DGVPointCtrl.Rows[j].Cells[field.Name].Value = //?
    }   
}

I can get the names of the field, but I don’t know how to actually access them using reflection. Any guidance would be appreciated.

  • 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-06-11T12:43:44+00:00Added an answer on June 11, 2026 at 12:43 pm

    If you say – cell names match to the properties of pointCommonInfo and pointSpecificInfo – then you should use GetProperties() instead of GetFields(). You can achieve it as following:

    Type commonType = typeof(PointCommonInformation);
    
    foreach (PropertyInfo item in commonType.GetProperties())
    {
            object propertyObject = item.GetValue(pointCommonInfo, null);
            string propertyValue = propertyObject == null ? string.Empty : propertyObject.ToString();
            DGVPointCtrl.Rows[j].Cells[item.Name].Value = propertyValue;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to change DataGridView cell ForeColor based on whether new cell value is >
In DataGridView I have CellValueChanged event, when user modify any cell value, this event
I have a DataGridView in a windows form. I defined 5 columns for this
I use DataGridView, and in some places I add control to it (e.g. textbox,
I have a datagridview being populated by a collection of objects. the values within
I have a DataGridView . I would like to update another cell on the
Using DataGridView with VB.Net 2008. I would like to freeze the left column so
I have a datagridview in which I want to copy some rows to a
DataGridView has an AlternatingRowsDefaultCellStyle, which works like a champ. But I need the opposite
The DataGridView control allows you to click the row headers and select the rows

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.