[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
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.
Re: [2008] Help somebody anybody!!
Why are you casting a DataSource to a DataView? You shouldn't do that.
Quote:
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)
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.
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!
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.
Re: [2008] Help somebody anybody!!
Table.Rows does not include the headers I believe.
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!