D
Dave
Apologies if this has come up before, but I can't find it if it has. I
am fairly new to .Net and am having problems with ghosts in the
datagrid.
Basically I have a find screen that accepts search criteria, then
interrogates a database to find all matching records. These are put
into a dataset, which has a dataview that is used as the datasource of
my datagrid, which is read only. The idea is that the user selects
which record they want to view.
The good news is this all works - well apart from the ghost that is.
Say I run a search that returns 10 records. These all show correctly
in the grid. Say I click on row 9 to highlight it, then go and run a
different search which returns just 5 records. They all display
correctly in the datagrid, then there is a gap and then the previously
highlighted cell remains, just hanging all by itself. It disappears
when you select a real cell, but I can't find any way of getting rid of
this 'ghost' programmatically. Any ideas?
If it helps, this is the code I use to populate the datagrid...
Dim conDatabase As New SqlClient.SqlConnection
Dim commSQL As New SqlClient.SqlCommand
Dim daSQL As New SqlClient.SqlDataAdapter
Dim dsData As New DataSet
conDatabase.ConnectionString = strConnectionString
conDatabase.Open()
commSQL.Connection = conDatabase
commSQL.CommandType = CommandType.StoredProcedure
commSQL.CommandText = "usp_SearchBooks"
' Set parameters
If Me.optTitleAll.Checked = False Then
commSQL.Parameters.Add("@Title", "%" &
Me.txtTitle.Text.Trim & "%")
End If
If Me.optSeriesAll.Checked = False Then
Dim clsComboClass As New ComboClass("", 0)
clsComboClass =
CType(Me.cboSeries.Items(Me.cboSeries.SelectedIndex), ComboClass)
commSQL.Parameters.Add("@SeriesID", clsComboClass.KeyValue)
End If
If Me.optAuthorAll.Checked = False Then
commSQL.Parameters.Add("@Author", "%" &
Me.txtAuthor.Text.Trim & "%")
End If
' run search
daSQL.SelectCommand = commSQL
daSQL.Fill(dsData, "Table")
' Show match list in datagrid.
Dim dvView As New DataView(dsData.Tables(0))
dvView.RowStateFilter = DataViewRowState.OriginalRows
dvView.AllowNew = False
Me.dgResults.DataSource = dvView
conDatabase.Close()
Any help is greatly appreciated.
Cheers
Dave
am fairly new to .Net and am having problems with ghosts in the
datagrid.
Basically I have a find screen that accepts search criteria, then
interrogates a database to find all matching records. These are put
into a dataset, which has a dataview that is used as the datasource of
my datagrid, which is read only. The idea is that the user selects
which record they want to view.
The good news is this all works - well apart from the ghost that is.
Say I run a search that returns 10 records. These all show correctly
in the grid. Say I click on row 9 to highlight it, then go and run a
different search which returns just 5 records. They all display
correctly in the datagrid, then there is a gap and then the previously
highlighted cell remains, just hanging all by itself. It disappears
when you select a real cell, but I can't find any way of getting rid of
this 'ghost' programmatically. Any ideas?
If it helps, this is the code I use to populate the datagrid...
Dim conDatabase As New SqlClient.SqlConnection
Dim commSQL As New SqlClient.SqlCommand
Dim daSQL As New SqlClient.SqlDataAdapter
Dim dsData As New DataSet
conDatabase.ConnectionString = strConnectionString
conDatabase.Open()
commSQL.Connection = conDatabase
commSQL.CommandType = CommandType.StoredProcedure
commSQL.CommandText = "usp_SearchBooks"
' Set parameters
If Me.optTitleAll.Checked = False Then
commSQL.Parameters.Add("@Title", "%" &
Me.txtTitle.Text.Trim & "%")
End If
If Me.optSeriesAll.Checked = False Then
Dim clsComboClass As New ComboClass("", 0)
clsComboClass =
CType(Me.cboSeries.Items(Me.cboSeries.SelectedIndex), ComboClass)
commSQL.Parameters.Add("@SeriesID", clsComboClass.KeyValue)
End If
If Me.optAuthorAll.Checked = False Then
commSQL.Parameters.Add("@Author", "%" &
Me.txtAuthor.Text.Trim & "%")
End If
' run search
daSQL.SelectCommand = commSQL
daSQL.Fill(dsData, "Table")
' Show match list in datagrid.
Dim dvView As New DataView(dsData.Tables(0))
dvView.RowStateFilter = DataViewRowState.OriginalRows
dvView.AllowNew = False
Me.dgResults.DataSource = dvView
conDatabase.Close()
Any help is greatly appreciated.
Cheers
Dave