Results 1 to 8 of 8

Thread: [2008] Help somebody anybody!!

  1. #1

    Thread Starter
    Addicted Member dani2's Avatar
    Join Date
    Feb 2005
    Location
    Sibiu.ro
    Posts
    191

    Question [2008] Help somebody anybody!!

    Can somebody explain to me why the following lines return different number?

    Code:
            
           Console.WriteLine(CType(dgv.DataSource, DataView).Count)
           Console.WriteLine(CType(dgv.DataSource, DataView).Table.Rows.Count)
    where dgv is a datagridview having a dataview as datasource.


    thanks
    Last edited by dani2; Mar 5th, 2008 at 07:51 AM.
    Home is where your Head is

  2. #2

    Thread Starter
    Addicted Member dani2's Avatar
    Join Date
    Feb 2005
    Location
    Sibiu.ro
    Posts
    191

    Re: [2008] Help somebody anybody!!

    The thing is I want to make a copy of a dataview by doing:

    dv_new = new Dataview(CType(dgv.DataSource, DataView).Table)

    So far so good except that the new dataview has one row less than the old one.
    Strange.
    Home is where your Head is

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Help somebody anybody!!

    Why are you casting a DataSource to a DataView? You shouldn't do that.

    dv_new = new Dataview(CType(dgv.DataSource, DataView).Table)
    Look at the members of DataView. It's expecting a Table but for some reason you're casting a DataSource as a DataView and grabbing its Table.

    Instead, just use
    Code:
    dv_new = new Dataview(MydataView.Table)
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Help somebody anybody!!

    Odd, I just wrote the same line a few minutes ago. A datasource is an object, so if the source is a dataview, it has to be cast to a dataview, or else you will just have an object, which has very few members.

    Dataview.Count will get the rows after the filter has been applied. Rows will get the entire set of rows in the underlying datatable. That may be the whole issue.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Addicted Member dani2's Avatar
    Join Date
    Feb 2005
    Location
    Sibiu.ro
    Posts
    191

    Re: [2008] Help somebody anybody!!

    The problem is that dv.count > dv.table.rows.count !? Why?? Even this is not the case I have no filter on the dataview.

    When shown in a datagridview everythings ok, but when I pass the dv.table to a CR I am missing the last row. I really really dont understand this. Help me!
    Home is where your Head is

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2008] Help somebody anybody!!

    I don't see anything obvious, but slap a breakpoint on the first Console.Writeline, highlight the dataview, and use Shift+F9 to look at the properties. You might have to tinker with what you are actually viewing, but you should be able to see the rows this way. Look at any column that would be variable enough to be informative, and see whether or not the problem becomes obvious.
    My usual boring signature: Nothing

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Help somebody anybody!!

    Table.Rows does not include the headers I believe.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  8. #8

    Thread Starter
    Addicted Member dani2's Avatar
    Join Date
    Feb 2005
    Location
    Sibiu.ro
    Posts
    191

    Re: [2008] Help somebody anybody!!

    I tried a different dataview in the application and I get equal results. So the problem must be in the was I populate the dataview.

    But why should matter the way the dataview is populated once I get the expected number of lines in the dataview? I mean dv.count and dv.table.rows.count are not the same thing?? Then why the datatable is missing the last row if the row exists in the dataview and I can see it in the datagridview?
    Again, no filters involved!
    Home is where your Head is

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