PC Review


Reply
Thread Tools Rate Thread

disappearing datagrid

 
 
wk6pack
Guest
Posts: n/a
 
      14th Feb 2007
Hi,

I have a datagrid that is populated from a query in SQL Server. The first
time I run the form, it appears, I make changes or view it and it is fine.
When I close the form and open it up again, the datagrid is not there to
see. I'm running the same code to populate it. What is happening? Any
suggestions?

thanks,
Will

Here is the code.



Dim ProcName As String = "PopulateDataGrid"

Dim daRoleDetail As SqlDataAdapter

Dim conn As SqlConnection

dsClass.Clear()

Me.dgClass.TableStyles.Clear()

Try

conn = New SqlConnection(UserInfoClass.sconn)

daRoleDetail = New SqlDataAdapter(SqlQuery, conn)

daRoleDetail.Fill(dsClass, TableName)



Dim ts As New DataGridTableStyle

ts.MappingName = TableName

ts.AlternatingBackColor = Color.WhiteSmoke

ts.SelectionBackColor = Color.Yellow

ts.SelectionForeColor = Color.Red

ts.PreferredRowHeight = 22

Dim colID As New DataGridTextBoxColumn

Dim colRoleDetail As New DataGridTextBoxColumn

Dim colclass As New DataGridTextBoxColumn

Call setDataGridProps(colID, "RoleDetailID", "ID", "", 75)

Call setDataGridProps(colRoleDetail, "RoleDetail", "Role Detail", "", 100)

Call setDataGridProps(colclass, "class", "Class", "", 200)

ts.GridColumnStyles.Add(colRoleDetail)

ts.GridColumnStyles.Add(colclass)

Me.dgClass.TableStyles.Add(ts)

ts = Nothing

Me.dgClass.SetDataBinding(dsClass, TableName)

Me.displayMsg(CStr(dsClass.Tables(TableName).Rows.Count) & " " & TableName &
" Records Loaded")

'clean up resources

If Not conn Is Nothing Then

conn.Close()

conn.Dispose()

End If

If Not daRoleDetail Is Nothing Then daRoleDetail.Dispose()


 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      15th Feb 2007
WK6pack,

A datagrid does not hold data, it is displaying it only from its datasource.
(the binding to that)

If the data is not anymore there (as it seems to me in your program), the
datagrid will as well not dispay that.

Cor

"wk6pack" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hi,
>
> I have a datagrid that is populated from a query in SQL Server. The first
> time I run the form, it appears, I make changes or view it and it is fine.
> When I close the form and open it up again, the datagrid is not there to
> see. I'm running the same code to populate it. What is happening? Any
> suggestions?
>
> thanks,
> Will
>
> Here is the code.
>
>
>
> Dim ProcName As String = "PopulateDataGrid"
>
> Dim daRoleDetail As SqlDataAdapter
>
> Dim conn As SqlConnection
>
> dsClass.Clear()
>
> Me.dgClass.TableStyles.Clear()
>
> Try
>
> conn = New SqlConnection(UserInfoClass.sconn)
>
> daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
>
> daRoleDetail.Fill(dsClass, TableName)
>
>
>
> Dim ts As New DataGridTableStyle
>
> ts.MappingName = TableName
>
> ts.AlternatingBackColor = Color.WhiteSmoke
>
> ts.SelectionBackColor = Color.Yellow
>
> ts.SelectionForeColor = Color.Red
>
> ts.PreferredRowHeight = 22
>
> Dim colID As New DataGridTextBoxColumn
>
> Dim colRoleDetail As New DataGridTextBoxColumn
>
> Dim colclass As New DataGridTextBoxColumn
>
> Call setDataGridProps(colID, "RoleDetailID", "ID", "", 75)
>
> Call setDataGridProps(colRoleDetail, "RoleDetail", "Role Detail", "", 100)
>
> Call setDataGridProps(colclass, "class", "Class", "", 200)
>
> ts.GridColumnStyles.Add(colRoleDetail)
>
> ts.GridColumnStyles.Add(colclass)
>
> Me.dgClass.TableStyles.Add(ts)
>
> ts = Nothing
>
> Me.dgClass.SetDataBinding(dsClass, TableName)
>
> Me.displayMsg(CStr(dsClass.Tables(TableName).Rows.Count) & " " & TableName
> & " Records Loaded")
>
> 'clean up resources
>
> If Not conn Is Nothing Then
>
> conn.Close()
>
> conn.Dispose()
>
> End If
>
> If Not daRoleDetail Is Nothing Then daRoleDetail.Dispose()
>
>



 
Reply With Quote
 
wk6pack
Guest
Posts: n/a
 
      15th Feb 2007
Hi Cor,

I am getting the data from the query every time I display the grid. It
works on the first run of the form. If I close the form and open the form
by clicking on the button again, the datagrid doesnt get displayed but it
shows a record count in a messagebox.
If I get data from the query the first time and it displays why wont it
display the second time running the same procedure call?

Where in my program do you think the data is not there anymore? I'm using a
"Select * from table" as SqlQuery.

---Getting the data from the database----
conn = New SqlConnection(UserInfoClass.sconn)
daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
daRoleDetail.Fill(dsClass, TableName

---setting the datagrid datasource with the dataset------
Me.dgClass.SetDataBinding(dsClass, TableName)

thanks,
Will

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> WK6pack,
>
> A datagrid does not hold data, it is displaying it only from its
> datasource. (the binding to that)
>
> If the data is not anymore there (as it seems to me in your program), the
> datagrid will as well not dispay that.
>
> Cor
>
> "wk6pack" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> Hi,
>>
>> I have a datagrid that is populated from a query in SQL Server. The
>> first time I run the form, it appears, I make changes or view it and it
>> is fine. When I close the form and open it up again, the datagrid is not
>> there to see. I'm running the same code to populate it. What is
>> happening? Any suggestions?
>>
>> thanks,
>> Will
>>
>> Here is the code.
>>
>>
>>
>> Dim ProcName As String = "PopulateDataGrid"
>>
>> Dim daRoleDetail As SqlDataAdapter
>>
>> Dim conn As SqlConnection
>>
>> dsClass.Clear()
>>
>> Me.dgClass.TableStyles.Clear()
>>
>> Try
>>
>> conn = New SqlConnection(UserInfoClass.sconn)
>>
>> daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
>>
>> daRoleDetail.Fill(dsClass, TableName)
>>
>>
>>
>> Dim ts As New DataGridTableStyle
>>
>> ts.MappingName = TableName
>>
>> ts.AlternatingBackColor = Color.WhiteSmoke
>>
>> ts.SelectionBackColor = Color.Yellow
>>
>> ts.SelectionForeColor = Color.Red
>>
>> ts.PreferredRowHeight = 22
>>
>> Dim colID As New DataGridTextBoxColumn
>>
>> Dim colRoleDetail As New DataGridTextBoxColumn
>>
>> Dim colclass As New DataGridTextBoxColumn
>>
>> Call setDataGridProps(colID, "RoleDetailID", "ID", "", 75)
>>
>> Call setDataGridProps(colRoleDetail, "RoleDetail", "Role Detail", "",
>> 100)
>>
>> Call setDataGridProps(colclass, "class", "Class", "", 200)
>>
>> ts.GridColumnStyles.Add(colRoleDetail)
>>
>> ts.GridColumnStyles.Add(colclass)
>>
>> Me.dgClass.TableStyles.Add(ts)
>>
>> ts = Nothing
>>
>> Me.dgClass.SetDataBinding(dsClass, TableName)
>>
>> Me.displayMsg(CStr(dsClass.Tables(TableName).Rows.Count) & " " &
>> TableName & " Records Loaded")
>>
>> 'clean up resources
>>
>> If Not conn Is Nothing Then
>>
>> conn.Close()
>>
>> conn.Dispose()
>>
>> End If
>>
>> If Not daRoleDetail Is Nothing Then daRoleDetail.Dispose()
>>
>>

>
>



 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      15th Feb 2007
Can you show us what you mean, (some code) with closing a form. Standard is
that closing the whole program. (The term open in VB.Net as far as I know
not used.

(Or is should be a file or something like that). What you can do is create a
new form.

Cor

"wk6pack" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Hi,
>
> I have a datagrid that is populated from a query in SQL Server. The first
> time I run the form, it appears, I make changes or view it and it is fine.
> When I close the form and open it up again, the datagrid is not there to
> see. I'm running the same code to populate it. What is happening? Any
> suggestions?
>
> thanks,
> Will
>
> Here is the code.
>
>
>
> Dim ProcName As String = "PopulateDataGrid"
>
> Dim daRoleDetail As SqlDataAdapter
>
> Dim conn As SqlConnection
>
> dsClass.Clear()
>
> Me.dgClass.TableStyles.Clear()
>
> Try
>
> conn = New SqlConnection(UserInfoClass.sconn)
>
> daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
>
> daRoleDetail.Fill(dsClass, TableName)
>
>
>
> Dim ts As New DataGridTableStyle
>
> ts.MappingName = TableName
>
> ts.AlternatingBackColor = Color.WhiteSmoke
>
> ts.SelectionBackColor = Color.Yellow
>
> ts.SelectionForeColor = Color.Red
>
> ts.PreferredRowHeight = 22
>
> Dim colID As New DataGridTextBoxColumn
>
> Dim colRoleDetail As New DataGridTextBoxColumn
>
> Dim colclass As New DataGridTextBoxColumn
>
> Call setDataGridProps(colID, "RoleDetailID", "ID", "", 75)
>
> Call setDataGridProps(colRoleDetail, "RoleDetail", "Role Detail", "", 100)
>
> Call setDataGridProps(colclass, "class", "Class", "", 200)
>
> ts.GridColumnStyles.Add(colRoleDetail)
>
> ts.GridColumnStyles.Add(colclass)
>
> Me.dgClass.TableStyles.Add(ts)
>
> ts = Nothing
>
> Me.dgClass.SetDataBinding(dsClass, TableName)
>
> Me.displayMsg(CStr(dsClass.Tables(TableName).Rows.Count) & " " & TableName
> & " Records Loaded")
>
> 'clean up resources
>
> If Not conn Is Nothing Then
>
> conn.Close()
>
> conn.Dispose()
>
> End If
>
> If Not daRoleDetail Is Nothing Then daRoleDetail.Dispose()
>
>



 
Reply With Quote
 
wk6pack
Guest
Posts: n/a
 
      15th Feb 2007
Hi Cor,

Private Sub FrmClass_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
call centerForm()
call PopulateDataGrid()
end sub

Here is the close form code.
ButtonClose:
dsTrainType.Dispose()

Me.dgTrainingType.Dispose()

Close()

thanks,
Will

"Cor Ligthert [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can you show us what you mean, (some code) with closing a form. Standard
> is that closing the whole program. (The term open in VB.Net as far as I
> know not used.
>
> (Or is should be a file or something like that). What you can do is create
> a new form.
>
> Cor
>
> "wk6pack" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> Hi,
>>
>> I have a datagrid that is populated from a query in SQL Server. The
>> first time I run the form, it appears, I make changes or view it and it
>> is fine. When I close the form and open it up again, the datagrid is not
>> there to see. I'm running the same code to populate it. What is
>> happening? Any suggestions?
>>
>> thanks,
>> Will
>>
>> Here is the code.
>>
>>
>>
>> Dim ProcName As String = "PopulateDataGrid"
>>
>> Dim daRoleDetail As SqlDataAdapter
>>
>> Dim conn As SqlConnection
>>
>> dsClass.Clear()
>>
>> Me.dgClass.TableStyles.Clear()
>>
>> Try
>>
>> conn = New SqlConnection(UserInfoClass.sconn)
>>
>> daRoleDetail = New SqlDataAdapter(SqlQuery, conn)
>>
>> daRoleDetail.Fill(dsClass, TableName)
>>
>>
>>
>> Dim ts As New DataGridTableStyle
>>
>> ts.MappingName = TableName
>>
>> ts.AlternatingBackColor = Color.WhiteSmoke
>>
>> ts.SelectionBackColor = Color.Yellow
>>
>> ts.SelectionForeColor = Color.Red
>>
>> ts.PreferredRowHeight = 22
>>
>> Dim colID As New DataGridTextBoxColumn
>>
>> Dim colRoleDetail As New DataGridTextBoxColumn
>>
>> Dim colclass As New DataGridTextBoxColumn
>>
>> Call setDataGridProps(colID, "RoleDetailID", "ID", "", 75)
>>
>> Call setDataGridProps(colRoleDetail, "RoleDetail", "Role Detail", "",
>> 100)
>>
>> Call setDataGridProps(colclass, "class", "Class", "", 200)
>>
>> ts.GridColumnStyles.Add(colRoleDetail)
>>
>> ts.GridColumnStyles.Add(colclass)
>>
>> Me.dgClass.TableStyles.Add(ts)
>>
>> ts = Nothing
>>
>> Me.dgClass.SetDataBinding(dsClass, TableName)
>>
>> Me.displayMsg(CStr(dsClass.Tables(TableName).Rows.Count) & " " &
>> TableName & " Records Loaded")
>>
>> 'clean up resources
>>
>> If Not conn Is Nothing Then
>>
>> conn.Close()
>>
>> conn.Dispose()
>>
>> End If
>>
>> If Not daRoleDetail Is Nothing Then daRoleDetail.Dispose()
>>
>>

>
>



 
Reply With Quote
 
CodeMonkey
Guest
Posts: n/a
 
      15th Feb 2007
Are you creating a new form (FrmClass) every time you open the form or
are you creating it once and then just .Show() it when you want to
display it?

wk6pack wrote:
> Hi Cor,
>
> Private Sub FrmClass_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> call centerForm()
> call PopulateDataGrid()
> end sub
>
> Here is the close form code.
> ButtonClose:
> dsTrainType.Dispose()
>
> Me.dgTrainingType.Dispose()
>
> Close()
>
> thanks,
> Will
>

 
Reply With Quote
 
wk6pack
Guest
Posts: n/a
 
      15th Feb 2007
I'm using frmClass.showdialogue(me) from the main form.


"CodeMonkey" <(E-Mail Removed)> wrote in message
news:573Bh.10714$(E-Mail Removed)...
> Are you creating a new form (FrmClass) every time you open the form or are
> you creating it once and then just .Show() it when you want to display it?
>
> wk6pack wrote:
>> Hi Cor,
>>
>> Private Sub FrmClass_Load(ByVal sender As Object, ByVal e As
>> System.EventArgs) Handles MyBase.Load
>> call centerForm()
>> call PopulateDataGrid()
>> end sub
>>
>> Here is the close form code.
>> ButtonClose:
>> dsTrainType.Dispose()
>>
>> Me.dgTrainingType.Dispose()
>>
>> Close()
>>
>> thanks,
>> Will
>>



 
Reply With Quote
 
CodeMonkey
Guest
Posts: n/a
 
      15th Feb 2007
Then my guess is that you are disposing of the controls on the form and
then trying to show that same form again. When you dispose the controls,
they are gone. You will have to create a new instance of the form before
you can Show it again.

wk6pack wrote:
> I'm using frmClass.showdialogue(me) from the main form.
>
>
> "CodeMonkey" <(E-Mail Removed)> wrote in message
> news:573Bh.10714$(E-Mail Removed)...
>> Are you creating a new form (FrmClass) every time you open the form or are
>> you creating it once and then just .Show() it when you want to display it?
>>
>> wk6pack wrote:
>>> Hi Cor,
>>>
>>> Private Sub FrmClass_Load(ByVal sender As Object, ByVal e As
>>> System.EventArgs) Handles MyBase.Load
>>> call centerForm()
>>> call PopulateDataGrid()
>>> end sub
>>>
>>> Here is the close form code.
>>> ButtonClose:
>>> dsTrainType.Dispose()
>>>
>>> Me.dgTrainingType.Dispose()
>>>
>>> Close()
>>>
>>> thanks,
>>> Will
>>>

>
>

 
Reply With Quote
 
wk6pack
Guest
Posts: n/a
 
      15th Feb 2007
Thanks CodeMonkey. That was the problem. I was disposing the datagrid when
the form closed. Once I removed it, it works like a charm.

thanks again.
Will

"CodeMonkey" <(E-Mail Removed)> wrote in message
news:Bj4Bh.10723$(E-Mail Removed)...
> Then my guess is that you are disposing of the controls on the form and
> then trying to show that same form again. When you dispose the controls,
> they are gone. You will have to create a new instance of the form before
> you can Show it again.
>
> wk6pack wrote:
>> I'm using frmClass.showdialogue(me) from the main form.
>>
>>
>> "CodeMonkey" <(E-Mail Removed)> wrote in message
>> news:573Bh.10714$(E-Mail Removed)...
>>> Are you creating a new form (FrmClass) every time you open the form or
>>> are you creating it once and then just .Show() it when you want to
>>> display it?
>>>
>>> wk6pack wrote:
>>>> Hi Cor,
>>>>
>>>> Private Sub FrmClass_Load(ByVal sender As Object, ByVal e As
>>>> System.EventArgs) Handles MyBase.Load
>>>> call centerForm()
>>>> call PopulateDataGrid()
>>>> end sub
>>>>
>>>> Here is the close form code.
>>>> ButtonClose:
>>>> dsTrainType.Dispose()
>>>>
>>>> Me.dgTrainingType.Dispose()
>>>>
>>>> Close()
>>>>
>>>> thanks,
>>>> Will
>>>>

>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Disappearing From DataGrid Cell =?Utf-8?B?VGhvbWFzIENvcmNvcmFu?= Microsoft Dot NET Framework Forms 0 9th Dec 2005 10:22 PM
DataGrid disappearing while viewing child row and parent row updated awesj@hotmail.com Microsoft Dot NET Framework Forms 0 6th Oct 2005 03:39 PM
Objects and code from datagrid disappearing! Mike Cooper Microsoft Dot NET 2 9th Mar 2004 04:21 PM
DataGrid Web Server control disappearing when handling Edit column event Patrick Microsoft VB .NET 0 13th Jan 2004 08:21 PM
Datagrid disappearing - client side coding Sue Microsoft ASP .NET 7 8th Dec 2003 07:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:18 AM.