How to add a gridview to a C winforms project with a list of objects as the datasource

0 votes

In Visual Studio 2015 community, I'm creating a winforms application with C#. In this project, I've created a class that looks like this:

public class EDIFile
    {
        public string fullInFilePath { get; set; }
        public string fullOutFilePath { get; set; }
        public string InfileName { get; set; }
        public string OutfileName { get; set; }
        public string UniqueID { get; set; }
        public DateTime infileDateTime { get; set; }
        public DateTime outfileDateTime { get; set; }
        public TimeSpan timeDiff { get; set; }
    }

I've compiled a list of this class. I'd want to have a gridview that is populated with the contents of this list after it's loaded. I checked online for a solution and found a few, but none of them worked for me. If you are able, please provide me with some clear instructions.

I still haven't figured out how to make it work for me. Based on the two responses, here is the code I've come up with so far:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProviderPayProject1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load_1(object sender, List<EDIFile> EDIFiles)
        {
            DataGridView dataGridView1 = new DataGridView();
            dataGridView1.AutoGenerateColumns = true;
            Controls.Add(dataGridView1);
            dataGridView1.DataSource = EDIFiles;
        }
    }
}

This is the code for "form2," which is invoked by "form1." All "form2" should do is load and populate a datagridview with data from a list supplied to it. Please assist me in determining what I'm doing incorrectly.

Jun 11 in C# by krishna
• 2,140 points
11 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C#

0 votes
1 answer

How to find the extension of a file in C#

Go to here https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension?redirectedfrom=MSDN&view=net-6.0#System_IO_Path_GetExtension_System_String_ string myFilePath = @"C:\MyFile.txt"; string ext ...READ MORE

answered Jun 21 in C# by jyoti
• 1,240 points
25 views
0 votes
1 answer

How do I specify the exit code of a console application in .NET

Simply put, you can return the exit ...READ MORE

answered Jun 11 in C# by pranav
• 2,580 points
46 views
0 votes
1 answer

How to practice a language like C#

I believe you should begin with personal ...READ MORE

answered Jun 13 in C# by krishna
• 2,140 points
15 views
0 votes
1 answer

How to convert JSON text into objects using C#

To make a class out of a ...READ MORE

answered Jun 13 in C# by krishna
• 2,140 points
22 views
0 votes
0 answers

How Convert VB Project to C#

I have a VB project that has ...READ MORE

Jun 11 in C# by jyoti
• 1,240 points
27 views
0 votes
0 answers

How to do a LIKE query with linq

How can I use Linq to conduct ...READ MORE

Jun 11 in C# by pranav
• 2,580 points
8 views
0 votes
1 answer

How to initialize a list of strings (List<string>) with many string values

Simply remove the () at the end. List<string> ...READ MORE

answered Jun 13 in C# by krishna
• 2,140 points
20 views
0 votes
3 answers

Trying to upload files using Selenium(C#)

You can try using Javascript Executor to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,120 points
4,506 views
+1 vote
1 answer

How to convert a list of vectors with various length into a Data.Frame?

We can easily use this command as.data.frame(lapply(d1, "length< ...READ MORE

answered Apr 4, 2018 in Data Analytics by DeepCoder786
• 1,720 points
808 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP