?
Solved

Why won't the datagridview always show all records in a dataset?

Posted on 2006-07-10
7
Medium Priority
?
366 Views
Last Modified: 2008-02-20
have a datagridview control that works fine if there are less than four lines displayed, but gets strange when there are four or more.

When a user changes the selected date, the dataset is purged and then refilled with data appropriate to that date.  I use Me.Test_for_VBdotNetDataSet_Dynamic.Clear() to clear it and Me.Native_TimeTrackingTableAdapter.Fill(Me.Test_for_VBdotNetDataSet_Dynamic.Native_TimeTracking, Me.Label5.Text, Me.MonthCalendar1.SelectionStart) to refill it.  The parameters are passed to the query that fills the dataset.  After refilling, the dataset has five records.  I can loop through those records and confirm that they are, in fact, what is in the database.  The datagridview is bound to the dataset.  When I check the number of lines in the datagridview though, (Me.DataGridView1.Rows.Count.ToString) I get four rows.  

Aparently, without regard to the number of records in the dataset the maximum number of rows that will display is four.  I have tested with four, five, and six returned records, but I do not have data for more than that.  Is there a parameter that I may have inadvertently set that prevents an initial display of more than a certain number of records?

This problem is preventing effective use of the tool I have developed and needs to be resolved ASAP.  I have looked and tested and pondered, and cannot see where in my code a problem might be.  At this point, I am beginning to believe that this may be a problem with the control itself.  If anyone has any ideas, please help me out.  Thanks in advance.

Trevor

0
Comment
Question by:tdhughesCPA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 34

Expert Comment

by:Sancler
ID: 17075093
Check out the .RowCount property

Roger
0
 

Author Comment

by:tdhughesCPA
ID: 17075158
That returns the same number of rows, and te same behavior is maintained where the datagridview will not exceed four lines - even when there is what should be a five line grid.

Thanks for your input

Trevor
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17076154
I cannot reproduce the behaviour you're reporting, and I haven't come across it in quite the form you are reporting it.  Which makes me doubt that it is a problem with the DataGridView itself.  It may be something to do with the bindings.  I think you need to do a specific check that the DataGridView is, at the stage at which you are having the problem, actually bound to the datatable that has been updated.

To check this I suggest that, after updating the dataset, you track back through the databinding to the actual datatable that the DataGridView IS bound to rather than just checking the row.count of the datatable that it SHOULD be bound to.  Unfortunately, this can be a convoluted process.  The DataGridView's immediate DataSource can be a BindingSource, or a DataSet, or a DataTable, or a Dataview.  If it is a BindingSource then the DataSource of that can be a DataSet, a DataTable, or a Dataview.  If it is a DataSet then the DisplayMember will be a specific DataTable within that.  If it is a DataView then the DataTable you want is the .Table of that.  

To track back, you have to know, or work out, what the precise sequence is in the case concerned.  It is possible to code for this generically, on the lines of

   If TypeOf MyDataGridView Is BindingSource Then
      Dim bs As BindingSource = CType(MyDataGridView.DataSource, BindingSource)

and so on.  But I have found it easier to code for the specific instance I am trying to debug (the code is only going to be temporary, for debugging purposes, anyway) on the lines

   MsgBox(MyDataGridView.DataSource.ToString)

and then, in the light of what that shows, code a line to deal with that and so on, until the actual DataTable is determined.  

I know that you KNOW what DataTable the DataGridView is bound to, and you've checked that, and it does have the extra rows in it.  So you may well feel that this convoluted extra check is a waste of time.  But if you've checked everything else, then perhaps there's nothing to lose.  And things don't always happen as we expect them to - e.g

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21911005

Roger
0
 
LVL 34

Accepted Solution

by:
Sancler earned 1000 total points
ID: 17077866
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question