Data Grid click events

P

patricia59

I am trying to use a datagrid control as a 'pick box' for
populating a series of textbox controls; would want to
assign an event such as a 'doubleclick event' to the
grid, and then reference the content of each data field
in order to store it to variables. It would be something
like this: Help appreciated very much.

Dim Varfield1,Varfield2,Varfield3 as string
Dim DataField1,DataField2,DataField3 as string

Dim DA1 as new DataAdapter("select lname,fname,idno from
mbrdata")
Dim DS1 As New DataSet("mbrdata")
DA1.Fill(DS1, "mbrdata")

Datagrid1.datasource = DS1
Datagrid1.databind()

Datafield1 = "DS1.idno" 'syntax for object reference
Datafield2 = "DS1.lname"
Datafield3 = "DS1.fname"

If Datagrid1.doubleclick then
varfield1 = datafield1
varfield2 = datafield2
varfield = datafield3
End if

Textbox1.text = datafield1
Textbox2.text = datafield2
Textbox3.text = datafield3
 
A

Anand Balasubramanian

Hi ,
Here is how you can do what you want

Public Class Form1
Inherits System.Windows.Forms.Form

'Windows Forms Generated Code

Dim oCmd As SqlClient.SqlCommand
Dim dAdapter As SqlClient.SqlDataAdapter
Dim mDS As New DataSet()
Dim var1, var2 As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

dAdapter = New SqlClient.SqlDataAdapter("select * from authors", strConn)
dAdapter.Fill(mDS, "AuthorInfo")

DataGrid1.DataSource = mDS
DataGrid1.DataMember = "AuthorInfo"
end sub

Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.DoubleClick

Dim temp As Integer
temp = DataGrid1.CurrentRowIndex

var1 = mDS.Tables(0).Rows(temp).Item(0)
var2 = mDS.Tables(0).Rows(temp).Item(1)

MsgBox(var1 + " " + var2)


End Sub

So when the user double clicks on the left margin, the double_click
procedure gets called and then we find out the index of the row that the
user clicked against and we retrieve the results.


Anand Balasubramanian
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks
 
P

patricia59

Thanks for the reply, but it does not seem to work.
Maybe because I am am using the web datagrid control? I
get 'currentrowindex is not a member of
system.web.ui.webcontrols.datagrid' on compile. I have
imported System.Windows.Forms. I have also tried a
selectedindexchanged event which passes the compiler, but
does not respond when grid is clicked.

I also have another question. When experimenting with
code on the web form, I sometimes put a clip of code for
testing purposes, in this case 'Textbox2.text
= "searching". When I go back and remove the code clip,
it continues to run as though the code was still there,
even after rebuild. Do you know why this is?
 
A

Anand Balasubramanian

HI,
I tested the code for a windows application and it works fine. Since you
are working on a web project, you should send your question to the ASPNET
news group as well.
Thanks
Anand Balasubramanian


Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks

----------------------------------------------------------------------------
----------------------------------------------------------------------
Content-Class: urn:content-classes:message
From: "patricia59" <[email protected]>
Sender: "patricia59" <[email protected]>
Subject: Data Grid click events
Date: Mon, 29 Sep 2003 10:04:01 -0700
Lines: 31
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOGq64cEmy74EI8TR6dHSZBUcVTJQ==
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:142231
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I am trying to use a datagrid control as a 'pick box' for
populating a series of textbox controls; would want to
assign an event such as a 'doubleclick event' to the
grid, and then reference the content of each data field
in order to store it to variables. It would be something
like this: Help appreciated very much.

Dim Varfield1,Varfield2,Varfield3 as string
Dim DataField1,DataField2,DataField3 as string

Dim DA1 as new DataAdapter("select lname,fname,idno from
mbrdata")
Dim DS1 As New DataSet("mbrdata")
DA1.Fill(DS1, "mbrdata")

Datagrid1.datasource = DS1
Datagrid1.databind()

Datafield1 = "DS1.idno" 'syntax for object reference
Datafield2 = "DS1.lname"
Datafield3 = "DS1.fname"

If Datagrid1.doubleclick then
varfield1 = datafield1
varfield2 = datafield2
varfield = datafield3
End if

Textbox1.text = datafield1
Textbox2.text = datafield2
Textbox3.text = datafield3



----------------------------------------------------------------------------
----------------------------------------------------------------------
X-Tomcat-ID: 677630877
References: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Anand Balasubramanian(MSFT))
Organization: Microsoft
Date: Wed, 01 Oct 2003 20:44:02 GMT
Subject: RE: Data Grid click events
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Lines: 35
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:142953
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi ,
Here is how you can do what you want

Public Class Form1
Inherits System.Windows.Forms.Form

'Windows Forms Generated Code

Dim oCmd As SqlClient.SqlCommand
Dim dAdapter As SqlClient.SqlDataAdapter
Dim mDS As New DataSet()
Dim var1, var2 As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

dAdapter = New SqlClient.SqlDataAdapter("select * from authors", strConn)
dAdapter.Fill(mDS, "AuthorInfo")

DataGrid1.DataSource = mDS
DataGrid1.DataMember = "AuthorInfo"
end sub

Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.DoubleClick

Dim temp As Integer
temp = DataGrid1.CurrentRowIndex

var1 = mDS.Tables(0).Rows(temp).Item(0)
var2 = mDS.Tables(0).Rows(temp).Item(1)

MsgBox(var1 + " " + var2)


End Sub

So when the user double clicks on the left margin, the double_click
procedure gets called and then we find out the index of the row that the
user clicked against and we retrieve the results.


Anand Balasubramanian
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks




----------------------------------------------------------------------------
----------------------------------------------------------------------
Content-Class: urn:content-classes:message
From: "patricia59" <[email protected]>
Sender: "patricia59" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: RE: Data Grid click events
Date: Thu, 2 Oct 2003 11:40:30 -0700
Lines: 75
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOJFKe2aBtXHRprRmatkt87VTKewg==
Newsgroups: microsoft.public.dotnet.languages.vb
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:143207
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Thanks for the reply, but it does not seem to work.
Maybe because I am am using the web datagrid control? I
get 'currentrowindex is not a member of
system.web.ui.webcontrols.datagrid' on compile. I have
imported System.Windows.Forms. I have also tried a
selectedindexchanged event which passes the compiler, but
does not respond when grid is clicked.

I also have another question. When experimenting with
code on the web form, I sometimes put a clip of code for
testing purposes, in this case 'Textbox2.text
= "searching". When I go back and remove the code clip,
it continues to run as though the code was still there,
even after rebuild. Do you know why this is?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top