Solved

Datagrid not displaying all rows

Posted on 2012-03-29
5
312 Views
Last Modified: 2012-04-17
I am using VS 2008, SQL CE and VB.
I have a DataGrid that is bound to via a recordset.

When I update the data source for the DataGrid, data in the DataGrid's visible rows are displayed correctly. However if you scroll down, the cells below are blank with a big "X". When you scroll back up, the rows that were displaying data are now replaced with big "X".

Here's the code:

Me.MyDataGrid.Doc = DockStyle.Bottom

Dim cmd as New SqlCECommand()
Dim conn as New SqlCEConnection()
Dim rs as SqlCEResultSet
conn.ConnectString ="Data Source = '\data.sdf'; mode=Exclusive;"
cmd.CommandText = "SELECT * FROM table1"
rs = cmdExecuteResultSet(ResultSetOptions.Scrollable or ResultSetOptions.Updatable)

if rs.HasRows then
   Me.MyDataGrid.DataSource = rs
End If

rs.Close()
rs = Nothing
conn.Close()

How do I display all the rows and make the scroll bar work?
0
Comment
Question by:mph23
  • 3
5 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37782920
Have you tried using a SqlCeDataAdapter to fill a DataTable and then use that as data source of the grid?
0
 

Author Comment

by:mph23
ID: 37783287
No, I didn't even know about them. I will try that - thanks for the tip!
0
 

Author Comment

by:mph23
ID: 37783669
I tried the following but it returns empty table:

        Dim cmd As New SqlCeCommand()
        Dim conn As New SqlCeConnection()
        Dim rs As SqlCeResultSet

        conn.ConnectionString = "Data Source = '\MyData.sdf'; mode=Exclusive;"
        conn.Open()

       cmd = conn.CreateCommand()
       cmd.CommandText = "SELECT * FROM tools"
       
       rs = cmd.ExecuteResultSet(ResultSetOptions.Scrollable Or ResultSetOptions.Updatable)

       If rs.HasRows = True Then
                Dim adp As New SqlCeDataAdapter(cmd)
                Dim ds As New System.Data.DataSet()

                adp.Fill(ds)
                Me.MyDataGrid.DataSource = ds
                MyDataGrid.Visible = True
                MyDataGrid.Refresh()
        End If
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 37786091
can you try:

Me.MyDataGrid.DataSource = ds.Tables(0)

Open in new window

0
 

Author Closing Comment

by:mph23
ID: 37854762
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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