Results 1 to 10 of 10

Thread: datagrid row count

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    7

    Question datagrid row count

    Hey all.

    I have a question that's been burning in my head (and my code) for a lil while now... hopefully someone can help me (before I go nuts)

    I have a custom object being returned by a webservice. I nab that custom object into a datagrid in my client app. All is good and fine with that, works quite nicely.. the problem is, I need to populate a checkedlistbox with that datagrid.

    So, I can either figure out how to use a datagrid as the source for the checkedlistbox (not easy with IList being required and such), or I can run through the datagrid (using it like a recordset) and populate the checkedlistbox. I can currently chuck in as many records as I want into the checkedlistbox from the datagrid, one at a time... this is wonderful, until I go past the end of the datagrid and it blows up on me .

    So, my question... how can I find the rowcount on a datagrid?? Or if anyone has any suggestions on other ways to do this, I'm MORE than open to ideas .

    Cheers all.

  2. #2
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    I believe datagridName.Items.Count will give you the record count you are looking for.

    Have you tried:
    checkboxlist1.DataSource = datagridName.DataSource
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    7
    in a round-a-bout way, that fully worked!!

    setting the datasource of the check box gives me the right number of rows... so, I set a variable to the number of rows in the checkbox, then set the datasource of it to nothing, clear it and use the rowCount variable I had to loop through the datagrid!!

    CHEERS!!

    total kludge way to do it, but I've spent 'bout 25 hours on it and I'm sick of looking at that piece of code

    thank you!!

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Y seting the datasource of checkedlistbox and then clearing it and looping through datagrid and repopulating the checkedlistbox?????
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    7
    I have to get the count of the datagrid... setting the datasource of the checkedboxlist to the datagrid gives me the total rows in the datagrid (checkedboxlist.items.count)... I then have a number to use as the maximum row value so I can loop through my datagrid and populate the checkedlistbox with the actual VALUES from the datagrid.

    Like I said, super round-a-bout way to do it, but it works.

  6. #6
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    You should be able to get the count from the datagrid.

    datagridName.Items.Count
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    and populate the checkedlistbox with the actual VALUES from the datagrid.
    So you mean that the checkedlistbox items comes from a column in datagrid, right?

    If so then you may set the checkedlistbox datasource to that of datagrid and its dispaly memeber to the coulmn you want to show.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    7
    Originally posted by Dmyze
    You should be able to get the count from the datagrid.

    datagridName.Items.Count
    Unfortunately, no... no items.count on a datagrid

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    7
    Originally posted by Lunatic3
    So you mean that the checkedlistbox items comes from a column in datagrid, right?

    If so then you may set the checkedlistbox datasource to that of datagrid and its dispaly memeber to the coulmn you want to show.
    Except, setting the datasource of the checkedlistbox to the datagrid source displayed ServerFunction.Property instead of the actual columns within the datagrid.

    checkedlistbox.datasource = datagrid.datasource is how I came to that.

  10. #10
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Thats the way it should be unless you define its dispaly member property.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

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