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.

commented: +++++++++ +1

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

Try and let me know, but remember, when working wit dgv control, best "tool" for populating it, is a dataTable. A good example you have here.

commented: ++++++ +1

Mitja, ok i'll watch it....

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;

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();

commented: ++++ +1

compiler doesn't know .DataBind() method

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;

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; }
        }
    } 
}

ArrayList......I'll remember it...Now a little experiment....

Speak at once - as in this case refer to a cell of dataGridView?

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? ))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.