Answer the question
In order to leave comments, you need to log in
How to bind data from listbox to DataGridView using bindingSource.DataSource?
Getting familiar with C#. There are, in my opinion, quite sensible youtube lessons from Defazze on the principles of programming in C # and in the 15th I stumbled in this code - the author does not respond:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Reflection;
using Microsoft.SqlServer.Server;
namespace Tree3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<Person> people=new List<Person>
{
new Person()
{
Familia="Ивановский",
Imia="Иван",
Pater="Иваныч",
Bday=new DateTime(1980,12,1)
},
new Person()
{
Familia="Иванов",
Imia="Иван",
Pater="Иваныч",
Bday=new DateTime(1981,10,18)
}
};
bindingSource1.DataSource=people;
}
}
}
using System;
namespace Tree3
{
public class Person
{
public DateTime Bday { get; set; }
public string Familia { get; set; }
public string Imia { get; set; }
public string Pater { get; set; }
}
}
Answer the question
In order to leave comments, you need to log in
The thing is that it was necessary not to drag the new bindingSource1 from the toolbar to the form and try to bind it, but directly in the DataGrid to set the data source class (in the presented menu - the object) Person, which will automatically create personBindingSource and connect the grid with the object. You can then edit the column headings from the default ones.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question