|
-
Jun 6th, 2008, 10:00 PM
#1
Thread Starter
New Member
[2005] Datagridview Click event question
I browsed through the forums and did not see a topic like this, if I missed it please point it out to me. Here is my situation. I have a form with several textboxes that reflect the columns of my SQL database. I also have a search function which opens a second form which has a datagridview that displays the query results. The first column of this DGV is the Primary key AND the record number found on the bindingnavigator from form one. What I'd would like to do is when a row is clicked in the DGV, is to navigate to the appropriate record on form1. Would anyone have an example on how to do this?
Thank you in advance.
-
Jun 6th, 2008, 10:31 PM
#2
Re: [2005] Datagridview Click event question
In your second form, declare a public property that returns the ID of the record selected. If the dialogue returns OK, read that property value and pass it to the BindingSource's Find method to find the index of the record with that ID. You then set the BindingSource's Position property to the index. E.g.
vb.net Code:
Using dlg As New DialogueForm If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then Me.BindingSource1.Position = Me.BindingSource1.Find("ID", dlg.SelectedID) End If End Using
-
Jun 7th, 2008, 08:50 AM
#3
Thread Starter
New Member
Re: [2005] Datagridview Click event question
Wow, I got a few questions at this point.
If I declare a public property on my second form, am I creating a third form as the new dialogueform?
My public property is expecting an identifier, I never used one before, so I am completely at a loss on this one.
Is this in the "set" part of the public property? i.e.
Code:
public property '<----Indentifier expected
Get
End Get
Set(ByVal value)
Using dlg As New DialogueForm
If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.BindingSource1.Position = Me.BindingSource1.Find("ID", dlg.SelectedID)
End If
End Using
End Set
End Property
I apologize for the noob type questions as this is my first project with VB and SQL.
-
Jun 7th, 2008, 12:21 PM
#4
Re: [2005] Datagridview Click event question
You're not supposed to be displaying the dialogue in the property. SelectedID is the property you're supposed to declare in the second form. That code is supposed to be in the first form and it gets the value of the SelectedID property from the second form.
-
Jun 7th, 2008, 12:44 PM
#5
Thread Starter
New Member
Re: [2005] Datagridview Click event question
Thank you for the reply. I found a pretty easy way to accomplish the same thing. I couldn't have done it without the idea you gave me, so I thank you for that 
Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim tst As Integer
DataGridView1.ReadOnly = True
tst = DataGridView1.CurrentRow.Cells(0).Value - 1
Form1.PraiseBindingSource.Position = tst
End Sub
-
Jun 7th, 2008, 01:01 PM
#6
Re: [2005] Datagridview Click event question
Hmmm... default instances. If you're going to use default instances then you'd better understand what they are because if you don't display a default instance in the first place then making changes to a default instance won't help you. It works in this case because your startup form is the default instance of its type but if you try to access Form2 that way from Form1, for instance, it will not work unless its the default instance of Form2 that you displayed in the first place.
-
Jun 7th, 2008, 01:12 PM
#7
Thread Starter
New Member
Re: [2005] Datagridview Click event question
I think I got what you mean. Yes form1 always loads the default instance programatically. Form2 is only accessed in a button.click event as a search engine (more or less)(New dynamic dataset pulled from the database itself). The results are shown in form2 and form2 is only opened in that button event. Does that make any sense?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|