Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange DataGrid behaviour

Status
Not open for further replies.

jantie78

Programmer
Jan 4, 2002
58
KR
Hi,

I have a strange problem when using a DataGrid, but first let me explain a little the situation. I've created a strong typed collection (inherited from CollectionBase). My collection contains instances of data-objects that retreive on-demand data from a database.

So far so good. Now I've a Windows.Form with a DataGrid on it. I fill up my Collection with some objects. Then I bind my Collection to the DataGrid (ex. grd.DataSource = myColl). And now my problems occures : some cell values of some columns are not displayed... I would expect that I've made an error but the strange thing is that when I minimize my Form, and restore it, all the values are displayed correctly. Same if I move another form in front of my DataGrid (and then move the form away), the values become visible.

I think I may conclude that my code contains no errors that return empty values, so I tried some more... I've put a button on my form that executes the following code : grd.Refresh '(grd is my DataGrid). When I click this button all values are magically displayed...

Can anybody give me some hints or a solution?? I'm thinking of calling the grd.Refresh after scrolling, but I can't find such an event.

Many thanx,

Jan
 
Code to fill my Collection and bind it to the DataGrid :
(Add Method just adds objects to the collection)
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim c As New OFRA.SmartCustomerCollection2()
c.Add(&quot;ID < 100&quot;)
grd.DataSource = c
grd.TableStyles(0).MappingName = grd.DataSource.GetType.Name

End Sub

Code I used to force the DataGrid to redraw itsself:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
grd.Refresh()
End Sub

Code for my Collection
Public Class SmartCustomerCollection2
Inherits CollectionBase

Public Sub New()
MyBase.New()
End Sub

Public Sub Add(ByVal WhereClause As String)
Dim odb As New DBGeneral()

Dim dr As OleDb.OleDbDataReader = odb.Command(&quot;SELECT id FROM Customer WHERE &quot; & WhereClause).ExecuteReader
Do While dr.Read
'Dim newID As New OFRA.CustomerID(dr(&quot;id&quot;))
Dim sc As New SmartCustomer(New CustomerID(dr(&quot;id&quot;)))
MyBase.List.Add(sc)
Loop
dr.Close()
odb.CloseConnection()
End Sub

Default Public Property Item(ByVal Index As Integer) As OFRA.SmartCustomer
Get
Return list.Item(Index)
End Get
Set(ByVal Value As OFRA.SmartCustomer)
'todo
End Set
End Property
End Class

And finally the code for my data-objects that loads on demand :
Public Class SmartCustomer
Inherits OFRA.Customer

Public Sub New(ByVal CustomerID As OFRA.CustomerID)
MyBase.ID = CustomerID
End Sub

Private Sub SmartCustomer_DataRequested() Handles MyBase.DataRequested
Dim cl As New CustomerLoader()
Dim c As New Customer()
c = cl.Load(Me.ID)
'Set properties
Me.FirstName = c.FirstName
Me.LastName = c.LastName
Me.Telephone = c.Telephone
Debug.WriteLine(&quot;T:&quot; & Me.Telephone)
Me.Version = c.Version
End Sub

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top