Click here to Skip to main content
15,906,558 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralBatch program Pin
David Mujica24-Aug-12 10:23
David Mujica24-Aug-12 10:23 
GeneralRe: Too many Connections in MySQL Pin
SPSandy24-Aug-12 6:34
SPSandy24-Aug-12 6:34 
AnswerRe: Too many Connections in MySQL Pin
Dave Kreskowiak24-Aug-12 4:23
mveDave Kreskowiak24-Aug-12 4:23 
QuestionWhat is the Visual Basic Code...this is urgent Pin
Member 937845723-Aug-12 15:31
Member 937845723-Aug-12 15:31 
AnswerRe: What is the Visual Basic Code...this is urgent Pin
Wes Aday23-Aug-12 16:00
professionalWes Aday23-Aug-12 16:00 
AnswerRe: What is the Visual Basic Code...this is urgent Pin
Dave Kreskowiak23-Aug-12 18:15
mveDave Kreskowiak23-Aug-12 18:15 
AnswerRe: What is the Visual Basic Code...this is urgent Pin
Joan M24-Aug-12 1:43
professionalJoan M24-Aug-12 1:43 
QuestionRows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Phoenix Hawke23-Aug-12 11:01
Phoenix Hawke23-Aug-12 11:01 
Ok folks I posted this question on the social.msdn.microsoft site over 7 hours ago. I got 24 views and no answers. So here I am at The Code Project hoping to find a VB.NET guru that save and make my day! The issue I am having is described below. Thanks in advance for any help provided! Big Grin | :-D

Quote:
I have an unbound DataGridView that has its VirtualMode property set to True and Visible property set to False. I am using a dynamically created DataTable that is populated by a query via the .Fill method of a SqlDataAdpater to cache the results of the query (see below).

Dim daQuery as New SqlDataAdapter(New SqlCommand(QueryText, MySqlConn))

QueryResults = New DataTable

daQuery.Fill(QueryResults)

daQuery = Nothing

I use the Rows.Clear and Columns.Clear methods of the DataGridView to clear the DataGridView each time before the query is executed (see below).

DataGridView1.Rows.Clear

DataGridView1.Columns.Clear

After the DataTable has been filled I recreate the Colmuns in the DataGridView via a For Each loop on the Columns collection of the DataTable and I use the Columns.Add method in the DataGridView to add each column to the DataGridView (see Below).

For Each QueryCol as DataColumn in QueryResults.Columns 'DataTable with Results

DataGridView1.Add("dgc" + QueryCol.ColumnName, QueryCol.ColumnName)

Next

I then create a number of blank rows that corresponds to the number of rows in the DataTable using the Rows.Add(n) method of the DataGridView (see below).

DataGridView1.Rows.Add(QueryResults.Rows.Count)

After all this is done I then set the DataGridView Visible property to True.

I have placed code in the DataGridView CellValueNeeded event to populate the cell data as it is displayed (see below).

Private Sub DataGridView1_CellValueNeeded(ByVal sender as Object, ByVal e as DataGridViewCellValueEventArgs) Handles DataGridView1.CellValueNeeded

e.Value = QueryResults.Rows(e.RowIndex).Item(e.ColumnIndex).ToString

'QueryResults is the DataTable holding the data from the query execution

End Sub

All this works fine the first time around. However, if I execute the same query a second time the DataGridView is some how retaining the data that was in it previously. The application hangs at the point where I am adding the suppose it blank rows to the DataGridView.Confused | :confused:

Before making the DataGridView visible I have checked the first row in the DataGridView by adding a single blank row and using the Immediate Window with the following statement (see below).

? DataGridView1.Rows(0).Cells(0).Value

Instead of returning an empty string it instead has the value of the first cell on the first row of the QueryResults DataTable. This should not be the case. I have tried setting the DataGridView DataSource property equal to Nothing with the same result as above. WTF | :WTF:

Can someone please help me with this issue?

AnswerRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Dave Kreskowiak23-Aug-12 18:24
mveDave Kreskowiak23-Aug-12 18:24 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Phoenix Hawke23-Aug-12 18:52
Phoenix Hawke23-Aug-12 18:52 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Bernhard Hiller23-Aug-12 23:05
Bernhard Hiller23-Aug-12 23:05 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Phoenix Hawke27-Aug-12 2:17
Phoenix Hawke27-Aug-12 2:17 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Bernhard Hiller27-Aug-12 2:34
Bernhard Hiller27-Aug-12 2:34 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Phoenix Hawke27-Aug-12 3:02
Phoenix Hawke27-Aug-12 3:02 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Bernhard Hiller27-Aug-12 3:19
Bernhard Hiller27-Aug-12 3:19 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Phoenix Hawke27-Aug-12 3:46
Phoenix Hawke27-Aug-12 3:46 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Dave Kreskowiak24-Aug-12 6:33
mveDave Kreskowiak24-Aug-12 6:33 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Phoenix Hawke27-Aug-12 2:30
Phoenix Hawke27-Aug-12 2:30 
GeneralRe: Rows.Clear is not working properly for an Unbound DataGridView in VB.NET 2005 Pin
Dave Kreskowiak27-Aug-12 4:54
mveDave Kreskowiak27-Aug-12 4:54 
Questionhow to block input value from user in inputbox or msgbox? Pin
lukaszo4422-Aug-12 21:56
lukaszo4422-Aug-12 21:56 
AnswerRe: how to block input value from user in inputbox or msgbox? Pin
Eddy Vluggen23-Aug-12 1:19
professionalEddy Vluggen23-Aug-12 1:19 
AnswerKeyboard emulator? Pin
David Mujica23-Aug-12 2:24
David Mujica23-Aug-12 2:24 
Questioncoverters from c# to vb6 Pin
Karthik Chintala22-Aug-12 20:43
Karthik Chintala22-Aug-12 20:43 
AnswerRe: coverters from c# to vb6 Pin
Eddy Vluggen23-Aug-12 1:17
professionalEddy Vluggen23-Aug-12 1:17 
AnswerRe: coverters from c# to vb6 Pin
Dave Kreskowiak23-Aug-12 2:20
mveDave Kreskowiak23-Aug-12 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.