Results 1 to 6 of 6

Thread: How to add data from Array to a Datagrid?

  1. #1
    Join Date
    Dec 2009
    Posts
    12

    How to add data from Array to a Datagrid?

    I am intermediate programmer in the programming world. I am learning the programming language like C++, Visual Basic, SQL, Core Java and PHP. I just love to do programming in any of this programming language and loves to learn new-new things also. This days i am working in Visual Basic, and i got stuck in a problem while making one demo project, and problem ishow can we add the data from the Array to a DataGrid or vice-versa? Please help me on this.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to add data from Array to a Datagrid?

    The bind of the data from array/arraylist to DataGrid or DBGrid is not that easy nor that hard. You should bound the DataGrid or DBGrid to the database recordset object. But , you should not bind a LocalArray to database grid. So, if you want bind the array, then save the Array in some temporary table in database and then open the recordset and do binding. Hope your problem will be solved.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to add data from Array to a Datagrid?

    I think you would be knowing how to populate data from or to a database into or from a datagrid/dbgrid. Once the ArrayList has been populated, you should set the DataSource property of the datagrid control to the ArrayList. Then the columns in the DataGrid control are populated which are based on the properties for which in-scope property accessor's exist. Hope your problem will be fix.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to add data from Array to a Datagrid?

    Actually you have not provided the complete information about your problem, means what your project is and what you really want to do?. Then if you ned to bind the arraylist to the datagrid, you firstly need to make a string
    array, populate it to the values, and after that bind the string array to
    the datagrid. I would give you simple code of binding them(not the complete code just example of it):
    ArrayList al1 = new ArrayList();
    al1.Add(allRecords("4").ToString());
    al1.Add(allRecords("5").ToString());

    DataGrid1.DataSource = al1.ToArray(typeof(string));
    DataGrid1.DataBind();
    Hope this code will give you idea of binding data and your problem get fix.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to add data from Array to a Datagrid?

    According to me, to bind the ArrayList with DataGrid, you need to contain the object which has/contain all the data. So, in order to bind the data of Arraylist, which will be stored in one of the objects; all the data members of the class should be implemented as properties. Then the arraylist will be able to bind the list of objects stored to the datagrid. There are 3steps to do this:
    1] Creating a class for the objects and it will be kept in the arraylist.
    2] Creating the list of objects which you want to bind to the datagrid
    3] After this all, just bind the datagrid.
    Hope your problem will be solved with this steps.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to add data from Array to a Datagrid?

    I also have problem related to the arraylist and datagrid. I developing a project, in which i have bind a DataGrid to the ArrayList, and after doing i got stuck in two problems:
    ->The DataGrid is showing that the Length property of the items instead of their text, so how i can do changes in that?
    ->And once done with binding, i added new elements to the ArrayList but the DataGrid is not getting refresh view- I had set the DataSource property of the DataGrid to Nothing and then done re-binding it to the ArrayList, then also it is not working? Need help please.
    Last edited by kelfro; 19-01-2010 at 10:23 AM.

Similar Threads

  1. Setting Chart Data points with an array?
    By CodeKid in forum Software Development
    Replies: 2
    Last Post: 03-07-2012, 10:03 PM
  2. Can array elements have different data types?
    By cloud101 in forum Software Development
    Replies: 1
    Last Post: 22-02-2012, 03:29 AM
  3. Datagrid VS Gridview
    By Techno Guru in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 12:42 PM
  4. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM
  5. Can I link my datagrid to a 2D array?
    By Aloke in forum Software Development
    Replies: 2
    Last Post: 07-10-2009, 11:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,488,141.66101 seconds with 16 queries