0

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

3
Contributors
15
Replies
17
Views
6 Years
Discussion Span
Last Post by vedro-compota
Featured Replies
  • 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 … Read More

  • 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 [URL="http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx"]here[/URL]. Read More

  • [QUOTE=vedro-compota;1437692]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 - [CODE]dataGridView1.DataSource = myMap.MapCityMass.ArrayOfCities;[/CODE] … Read More

  • [QUOTE=vedro-compota;1444742]compiler doesn't know .DataBind() method[/QUOTE] Sorry for that I thought you were asking for Asp.Net's Gridview I pasted a link below that surely helps you [url]http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/860e8b9a-6aea-410b-b3ed-acf9f43a6110/[/url] Read More

  • This is how you bind objects: [CODE] 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 … Read More

1

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.

Votes + Comments
+++++++++
0

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

1

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.

Votes + Comments
++++++
0

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 by vedro-compota: n/a

1

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

Votes + Comments
0

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

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 by vedro-compota: n/a

1

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

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.