Results 1 to 4 of 4

Thread: [2.0] datagridview column bind?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    [2.0] datagridview column bind?

    I have an arraylist as my datasource.
    Obviously you cannot directly bind this to the datagridview, so I have to go through each item in the collection, then add the items in the datagridview.

    question is, how can I specify which column to place the current data in the datagridview?

    so if we have col1, col2, col3, I wish to add the items in col2

    I tried:

    ..

    this.theDataGridView.Rows[counter].Cells["MyColumn2"].Value = currentObject.ToString();

    ..

    but going round after the first time, throws an argumentoutofrange exception in the Cells.

    thanks!
    Last edited by Techno; Jul 25th, 2006 at 12:27 PM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: [2.0] datagridview column bind?

    got it, had to add a new row in the foreach loop

    *embarrased*

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] datagridview column bind?

    Um, of course you CAN actually bind the ArrayList to the grid. The only requirement is that the objects in collection expose the values you want to display through public properties.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: [2.0] datagridview column bind?

    well I wasnt referring to objects, just simple strings like "hi" "hello" etc..., not collections of object
    shoulve made it clearer, my apologese

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width