Resolved Help with data not showing in DGV

Jfisher387

Member
Joined
Dec 14, 2022
Messages
21
Programming Experience
Beginner
I am creating a DGV and filling it with data from a dataset. I have done this several times within this application and did not run into the issues I am now. basically the goal is to search through the data for a "Status" of "Active", and then check that the sales rep string matches. once this happens add that data to my list. after it reads through the entire datatable it sets the data source.

my issue is that 3 of the fields are just empty all the way through. I cannot figure out why some display and some do not. I have tried several different approaches with the code to make it work but i just cannot figure it out.

form load:
private void Active_Jobs_Load(object sender, EventArgs e)
        {
            //TODO: Highlight due dates that are past due in red, yellow if within 7 days from being due?

            this.jobTableAdapter.Fill(this.pRODUCTIONDataSet2.Job);
            foreach (DataRow row in pRODUCTIONDataSet2.Tables[0].Rows)
            {
                if (row["Status"].ToString() == "Active")
                {

                    if (row["Sales_Rep"].ToString() == "JOEDOL")
                    {
                        ActiveJobsReport job = new ActiveJobsReport();
                        job.Order_Date =  Convert.ToString(row["Order_Date"]);
                        job.JobNumber =   Convert.ToString(row["Job"]);//
                        job.Customer =    Convert.ToString(row["Customer"]);
                        job.Part_Number = Convert.ToString(row["Part_Number"]);
                        job.Description = Convert.ToString(row["Description"]);
                        job.OrderQty =    Convert.ToInt32(row["Order_Quantity"]);//
                        job.Price =       Convert.ToInt32(row["Total_Price"]);//
                        jobList.Add(job);
                    
                    }
                }
            }
          
            dataGridView1.DataSource = jobList;
            dataGridView1.Refresh();
        }

Screenshot_2.png




activejobsreport class:
  public class ActiveJobsReport
    {
        public string Order_Date { get; set; }
        public string JobNumber { get; set; }
        public string Customer { get; set; }
        public string Part_Number { get; set; }
        public string Description { get; set; }
        public int OrderQty { get; set; }
        public int Price { get; set; }

    }
 
Since your field names in the screenshot on the left don't match the column names in your screenshot on the right, and those same columns which have mismatched names are also blank, but the columns exist, that would suggest to me that you don't havr the correct data field names in your column definitions.

Check your DataPropertyName values in each of your columns.
 
Ok that worked. i tried it out on the job field. Why does that have to match though? I don't care what the field is called. I care what is inside of the field. the name of the field is just a identifier for me to read i thought?
 
How will the framework know how to find what data to display? It uses the DataPropertyName.

The HeaderText and Name can be completely different from the DataPropertyName. It's been years since I've used the DGV, but there is a hierarchy of which of those 3 properties the DGV chooses as the default column header text.
 
interesting. well, I will definitely note this info. Thank you for your quick responses. I swear I have instances somewhere in my program this doesn't seem to jive.. If i find that to be true ill report back.
 
I swear I have instances somewhere in my program this doesn't seem to jive.

You don't. If data is bound to a DataGridView then the DataPropertyName contains the name of the data source column or property that grid column is bound to. That's how it works and it doesn't work any other way.
 

Latest posts

Back
Top Bottom