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, 2022 in C# by krishna
• 2,820 points
842 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, 2022 in C# by jyoti
• 1,240 points
344 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, 2022 in C# by pranav
• 2,590 points
2,005 views
0 votes
1 answer

How to practice a language like C#

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

answered Jun 13, 2022 in C# by krishna
• 2,820 points
260 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, 2022 in C# by krishna
• 2,820 points
337 views
0 votes
0 answers

How Convert VB Project to C#

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

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

How to do a LIKE query with linq

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

Jun 11, 2022 in C# by pranav
• 2,590 points
236 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, 2022 in C# by krishna
• 2,820 points
1,155 views
0 votes
0 answers

Print Excel Worksheet/Workbook

I'm attempting to make a C# Winform ...READ MORE

Oct 31, 2022 in Others by Kithuzzz
• 38,010 points
510 views
0 votes
1 answer

Microsoft.Office.Interop.Excel for Office 2007

Each client must install the  2007 Microsoft ...READ MORE

answered Nov 5, 2022 in Others by narikkadan
• 63,420 points
1,088 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP