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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:40:10+00:00 2026-06-15T01:40:10+00:00

I’m trying to get firstName, lastName, assocID, etc. to display in a datagrid on

  • 0

I’m trying to get “firstName, lastName, assocID, etc.” to display in a datagrid on my form. I’m a new programmer/script kiddie, sorry if this is a dumb question. I just don’t know how to call associateList.firstName to a readable datagrid entry.

I would like the datagrid to use every associate in associateList if possible. Was considering a basic counter on an index refrence somehow.

Other input on how I’m writing my code is appreciated as well. I’m new, and self-taught.

In short : I want the associates to display in the datagrid using columns to separate the information.

The datagrid name is dataGridAssociates on the windows form.

namespace Associate_Tracker
{
    public partial class Form1 : Form
    {
        public class Associate
        {
            //No idea wtf {get; set;} does but I read that I need it?

            public string firstName { get; set; }
            public string lastName { get; set; }
            public string assocRFID { get; set; }
            public int assocID { get; set; }
            public bool canDoDiverts { get; set; }
            public bool canDoMHE { get; set; }
            public bool canDoLoading { get; set; }
        }

        public Form1()
        {
            InitializeComponent();
        }

        private void buttonAddAssoc_Click(object sender, EventArgs e)
        {
            #region Datagrid Creation -- Name: dt
            DataTable dt = new DataTable();
            dt.Columns.Add("First Name");
            dt.Columns.Add("Last Name");
            dt.Columns.Add("RFID");
            dt.Columns.Add("Associate ID#");
            dt.Columns.Add("Diverts");
            dt.Columns.Add("MHE");
            dt.Columns.Add("Loading");
            dataGridAssociates.DataSource = dt;
            #endregion

            //First & Last name splitter
            string allValue = textBoxAssocName.Text;
            string firstNameTemp = String.Empty;
            string lastNameTemp = String.Empty;
            int getIndexOfSpace = allValue.IndexOf(' ');

            for (int i = 0; i < allValue.Length; i++)
            {
                if (i < getIndexOfSpace)
                {
                    firstNameTemp += allValue[i];
                }
                else if (i > getIndexOfSpace)
                {
                    lastNameTemp += allValue[i];
                }
            }
            firstNameTemp = firstNameTemp.Trim(); // To remove empty spaces
            lastNameTemp = lastNameTemp.Trim();   // To Remove Empty spaces
            //End splitter

            int assocIDTemp;    //TryParse succeeds
            bool assocIDparse;  //Bool for TryParse

            //Try Parsing Associate ID to an integer
            //Includes catch -> return
            assocIDparse = int.TryParse(textBoxAssocID.Text, out assocIDTemp);
            if (assocIDparse == false)
            {
                MessageBox.Show("Please use only numbers in the AssocID input");
                return;
            }
            var associateList = new List<Associate>();
            associateList.Add(new Associate
            {
                firstName = firstNameTemp,
                lastName = lastNameTemp,
                assocID = assocIDTemp,
                canDoDiverts = checkBoxDiverts.Checked,
                canDoMHE = checkBoxMHE.Checked,
                canDoLoading = checkBoxLoading.Checked,
            });
            textBoxAssocID.Clear();
            textBoxAssocName.Clear();
            textBoxRFID.Clear();
        }
    }
}
  • 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-15T01:40:11+00:00Added an answer on June 15, 2026 at 1:40 am

    I won’t say that this is the most elegant way of doing this but with WinForms and DataGridView control you can use the BindingSource control to do this. I have added a sample below with the modified code to achieve what you are trying to do.

    The key points to note here are as follow:

    • Notice the BindingSource instance which is created at the top. This is the element that I have used to bind to the DataGridView in the constructor
    • In the constructor, I attach a instance of an Associate list to the DataSource of the BindingSource
    • In the constructor again, I attach the BindingSource to the DataSource of the DataGridView control.
    • Finally at the bottom of the button event, I first create an instance of Associate using AddNew in the BindingSource (this will automatically create in the Asociate list instance create in the constructor) and assign their appropriate values to it which are then populated in the DataGridView directly.

    Any problem let me know.

        readonly BindingSource _bindingSource = new BindingSource();
    
        public Form1()
        {
            InitializeComponent();
            _bindingSource.DataSource = new List<Associate>();
            dataGridAssociates.DataSource = _bindingSource;
        }
    
        public class Associate
        {
            public string firstName { get; set; }
            public string lastName { get; set; }
            public string assocRFID { get; set; }
            public int assocID { get; set; }
            public bool canDoDiverts { get; set; }
            public bool canDoMHE { get; set; }
            public bool canDoLoading { get; set; }
        }
    
        private void buttonAddAssoc_Click(object sender, EventArgs e)
        {
            //First & Last name splitter
            string allValue = textBoxAssocName.Text;
            string firstNameTemp = String.Empty;
            string lastNameTemp = String.Empty;
            int getIndexOfSpace = allValue.IndexOf(' ');
    
            for (int i = 0; i < allValue.Length; i++)
            {
                if (i < getIndexOfSpace)
                {
                    firstNameTemp += allValue[i];
                }
                else if (i > getIndexOfSpace)
                {
                    lastNameTemp += allValue[i];
                }
            }
            firstNameTemp = firstNameTemp.Trim(); // To remove empty spaces
            lastNameTemp = lastNameTemp.Trim(); // To Remove Empty spaces
            //End splitter
    
            int assocIDTemp; //TryParse succeeds
            bool assocIDparse; //Bool for TryParse
    
            //Try Parsing Associate ID to an integer
            //Includes catch -> return
            assocIDparse = int.TryParse(textBoxAssocID.Text, out assocIDTemp);
            if (assocIDparse == false)
            {
                MessageBox.Show("Please use only numbers in the AssocID input");
                return;
            }
    
            var obj = (Associate) _bindingSource.AddNew();
            if (obj != null)
            {
                obj.firstName = firstNameTemp;
                obj.lastName = lastNameTemp;
                obj.assocID = assocIDTemp;
                obj.canDoDiverts = checkBoxDiverts.Checked;
                obj.canDoMHE = checkBoxMHE.Checked;
                obj.canDoLoading = checkBoxLoading.Checked;
            }
    
            textBoxAssocID.Clear();
            textBoxAssocName.Clear();
            textBoxRFID.Clear();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.