Hello dear programmers!
My question isn't unique and i have read many articles about datagridview , but i've understood nothing ((
Please - tell me - how to load an array in datagridview ?
All i've understood is that for this I should use datasourse property -

dataGridView1.DataSource = myMap.MapCityMass.ArrayOfCities;

but how to start loading?
thank you for your answers!)

Which array exactly? Or string[], ArrayList, generic List ?
And how many columns has your dgv?

Just for your info, for populating dgv, its best practice to use DataSet (or DataTable). Its specially designed for that, becuase you can create columns and rows, its actually a copy of dgv. In arrays you CANNOT have any columns, so populating its hard - or better said - useless.

Comments
+++++++++

I think if i understand how to do it with string array - i'll grasp in other cases........may be)

ok. should i o load the array into a dataTable ? as understand - I should do something like this -

DataTable dataTable = new DataTable();

dataTable.LoadDataRow(array, true);//Pass array object to LoadDataRow method

return dataTable;

Edited 5 Years Ago by vedro-compota: n/a

Hello dear programmers!
My question isn't unique and i have read many articles about datagridview , but i've understood nothing ((
Please - tell me - how to load an array in datagridview ?
All i've understood is that for this I should use datasourse property -

dataGridView1.DataSource = myMap.MapCityMass.ArrayOfCities;

but how to start loading?
thank you for your answers!)

string[] str = {"a","b","c","d"};
Gridview1.DataSource = str;
Gridview1.DataBind();

Comments

AhmedSaud + to you - but how to bind array of object ?
for strings one - it's enough this -

string[] str = { "a", "b", "c", "d" };
dataGridView1.DataSource =str ;

thanks) but how to bind array of objects? for the strings one it's enough -

string[] str = { "a", "b", "c", "d" };
dataGridView1.DataSource = str;

Edited 5 Years Ago by vedro-compota: n/a

This is how you bind objects:

namespace Jan14DGVpopulation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            a();
        }

        private void a()
        {
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            list.Add(new BindingObject(1, "One", null));
            list.Add(new BindingObject(2, "Two", null));
            list.Add(new BindingObject(3, "Three", null));
            dataGridView1.DataSource = list;
        }
    }

    public class BindingObject
    {
        private int intMember;
        private string stringMember;
        private string nullMember;
        public BindingObject(int i, string str1, string str2)
        {
            intMember = i;
            stringMember = str1;
            nullMember = str2;
        }
        public int IntMember
        {
            get { return intMember; }
        }
        public string StringMember
        {
            get { return stringMember; }
        }
        public string NullMember
        {
            get { return nullMember; }
        }
    } 
}

This is how you bind objects:

namespace Jan14DGVpopulation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            a();
        }

        private void a()
        {
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            list.Add(new BindingObject(1, "One", null));
            list.Add(new BindingObject(2, "Two", null));
            list.Add(new BindingObject(3, "Three", null));
            dataGridView1.DataSource = list;
        }
    }

    public class BindingObject
    {
        private int intMember;
        private string stringMember;
        private string nullMember;
        public BindingObject(int i, string str1, string str2)
        {
            intMember = i;
            stringMember = str1;
            nullMember = str2;
        }
        public int IntMember
        {
            get { return intMember; }
        }
        public string StringMember
        {
            get { return stringMember; }
        }
        public string NullMember
        {
            get { return nullMember; }
        }
    } 
}

this is a very good example!))
please tell me - how in this case refer to a cell to get data from it? ))

This question has already been answered. Start a new discussion instead.