|
-
Mar 5th, 2008, 07:45 AM
#1
Thread Starter
Addicted Member
[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
-
Mar 5th, 2008, 08:00 AM
#2
Thread Starter
Addicted Member
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
-
Mar 5th, 2008, 11:11 AM
#3
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)
-
Mar 5th, 2008, 03:28 PM
#4
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
 
-
Mar 5th, 2008, 06:16 PM
#5
Thread Starter
Addicted Member
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
-
Mar 5th, 2008, 07:06 PM
#6
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
 
-
Mar 5th, 2008, 09:40 PM
#7
Re: [2008] Help somebody anybody!!
Table.Rows does not include the headers I believe.
-
Mar 6th, 2008, 05:01 AM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|