I cannot Load values into lables with Data from a Datagridview, after searching the Datagridview with a textbox.

  • Thread starter Thread starter Gary Simpson
  • Start date Start date
G

Gary Simpson

Guest
Hi Good People

On my form I have a DataGridView that I have dragged onto the form via the Data source column, I have also dragged Labels onto the form not all, Only the data I wish to see.

When I click on a row in the DataGridView the Labels work well they show all the data I require.

I also put a textbox on the form to search a particular Column in the DataGridView. this works fine, it narrows down what I am looking/Searching for in the DataGridView.

But here come my issue...

Once I have used the textbox, And I click on the DataGridView row, the Labels are no Longer Updated.

Can someone please help with this Issue

The code from my textbox is...

Private Sub FetchName(Name As String)
SQL.AddParam("@Cust", "%" & Name & "%")
SQL.ExecQuery("Select * FROM JobsCompleted " &
"WHERE Name LIKE @Cust")
dgvJobsCompleted.DataSource = SQL.SQLDT

End Sub

Private Sub txtFilterName_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtFilterName.KeyPress
FetchName(txtFilterName.Text)
End Sub


I have also tried get values from the DataGridView into the Labels with this code. But I still get the same Issue

Private Sub GetName()

SQL.ExecQuery("SELECT * FROM JobsComplete ")

If SQL.RecordCount < 1 Then Exit Sub

Dim index As Integer
index = index
Dim SelectedRow As DataGridViewRow
SelectedRow = dgvJobsCompleted.Rows(index)
Dim SelectedColumn As DataGridViewCell
SelectedColumn = dgvJobsCompleted.Rows(0).Cells(index)

For Each r As DataRow In SQL.SQLDT.Rows
lbJobCompletedID.Text = r("JobCompletedID").ToString
lbJobID.Text = r("JobID").ToString
lbName.Text = r("Name").ToString
lbHouseNameOrNo.Text = r("HouseNameOrNo").ToString
lbRoadName.Text = r("RoadName").ToString
lbTown.Text = r("Town").ToString
lbCounty.Text = r("County").ToString
lbPostcode.Text = r("Postcode").ToString
lbPriceOfJob.Text = r("PriceOfJob").ToString
lbDiscount.Text = r("Discount").ToString
lbSubTotal.Text = r("SubTotal").ToString
lbVAT.Text = r("VAT").ToString
lbTotalPartsPrice.Text = r("TotalPartsPrice").ToString
lbTotalPrice.Text = r("TotalPrice").ToString
lbUsername.Text = r("Username").ToString
lbDateUpdated.Text = GetDateFromString("DateUpdated").ToString()

Next

End Sub

Kind Regards Gary


Gary Simpson

Continue reading...
 

Similar threads

K
Replies
0
Views
186
Kashif Sattar
K
V
Replies
0
Views
131
VB Novice Hendri
V
C
Replies
0
Views
183
Claude du Québec
C
V
Replies
0
Views
90
VB Novice Hendri
V
Back
Top