|
-
Jun 18th, 2004, 04:00 AM
#1
Thread Starter
Addicted Member
Datagrid Question
Hi All,
I have created a form with a datagrid. What i would like to do is double click on a row within the datagrid to open another form displaying the contents of that record.
I already have the other form to display the selected record but I don't know how to get the value of cell containing the primary key so i can open the form and jump to that record.
any help or examples appreciated.
-
Jun 18th, 2004, 09:04 AM
#2
Frenzied Member
I'm in the middle of pulling some data, so you have to give me a while so I can actually look and see what exactly it is, but the datagrid has a double click method, and it also has a CurrentCell property with the row and column number in it...so:
get the cell data by:
CellData = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 23rd, 2004, 05:31 AM
#3
Thread Starter
Addicted Member
Many thanks for your reply, it got me on the right track and I am now starting to make some progress.
-
Aug 22nd, 2004, 08:17 PM
#4
Lively Member
please help a newbie!!!
hi!
Just a few questions...what is the datatype of the variable CellData? Where will i put this code? in the datagrid.doubleclick event or in the new form that will pop up? please help a newbie! Thanks!
-
Aug 23rd, 2004, 03:08 AM
#5
Thread Starter
Addicted Member
celldata is a public variable stored within a module.
This is then available for use in any of the forms. Remember to re-set it everytime you load your form.
-
Aug 23rd, 2004, 03:36 AM
#6
Lively Member
thanks for replying! Since you've been nice enough to share your knowledge with me, would you mind sharing the code you used in your program? It's ok if you don't want to. I understand. But I'd be very grateful if you do. Thanks! Thanks!
PS:
1. Was your second form in datagrid also or you used textboxes/comboboxes?
2. Was your datagrid bound to a dataset or a datatable?
Last edited by siomai; Aug 23rd, 2004 at 04:28 AM.
-
Aug 23rd, 2004, 05:01 AM
#7
Thread Starter
Addicted Member
Hello again,
i will explain how i achieved it. I had two forms, the first contained a datagrid containing the records. Once i double clicked a record, the second form then opened showing all the details for the record i had chosen.
VB Code:
Private Sub grdData_Doubleclick(ByVal sender As Object, ByVal e AS System.EventArgs) Handles grdData.DoubleClick
'grab the row
CellData = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)
If CellData = '' Then
msgBox("No Record")
Else
'make call to public function in Module
Call Open_Form1
End If
End Sub
Now you need to add a module to your project and make sure you have the function Open_Form1 (or whatever you call it)
VB Code:
'you need to declare you celldata variable here
Public celldata as Int
Public Function Open_Form1 ()
'open a new instance of the form
Dim frm1 As New frm1
frm1.Show()
'on my form I have a combobox so i use this to pass the value of celldata to.
frm1.cboData.SelectedValue = celldata
End Function
It's a bit rough and ready but it works.
Hope this helps
Last edited by dagoose; Aug 23rd, 2004 at 05:27 AM.
-
Aug 23rd, 2004, 08:23 PM
#8
Lively Member
hi again!
I'm having a blue line in this line:
It says "Expression Expected."
Is this in vb.net code? Cause single quote is for comments. Think it's commenting the succeeding code out. Btw, I declared variable celldata as integer. Was that right?
Last edited by siomai; Aug 23rd, 2004 at 10:12 PM.
-
Aug 23rd, 2004, 08:38 PM
#9
Lively Member
Ok...instead of putting the ' ' in the expression, I used 0. It didn't give me any errors but did not even open my form. what happend?
Also, after (for example) I have already editted the data in my second form, how will I overwrite the old celldata with the new and editted data? Please help!
-
Aug 24th, 2004, 02:53 AM
#10
Thread Starter
Addicted Member
oops! should have been "" not ''
did you put the function inside the module?
-
Aug 25th, 2004, 07:39 PM
#11
Lively Member
got an error
hi dagoose!
I changed my code and placed "not" in the expression...i got this error:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "not" to type 'Double' is not valid.
Hope you could help me...i need this very badly. Thanks in advance!
-
Aug 25th, 2004, 07:44 PM
#12
Lively Member
hope you'd reply soon...
btw, what is 'Int' in your code?
-
Aug 26th, 2004, 02:44 AM
#13
Thread Starter
Addicted Member
int = Integer
You mis-understood my post, don't use the word not, use "" (empty quotes).
-
Aug 26th, 2004, 03:33 AM
#14
Lively Member
ok i used revised my code but still i got this error:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "" to type 'Double' is not valid.
why? what am i doing wrong?
-
Aug 26th, 2004, 03:52 AM
#15
Thread Starter
Addicted Member
could be that you field in the database is a different datatype, try changing to:
Public celldata as String
-
Aug 26th, 2004, 09:43 PM
#16
Lively Member
-
Aug 27th, 2004, 01:43 AM
#17
Lively Member
help! please! I can't do it...
i'm getting dizzy already....please help me! anyone?
-
Aug 29th, 2004, 06:48 PM
#18
Lively Member
double click on datagrid (CONTINUATION)
please help me do this...
I'm able to doubleclick on my datagrid and transfer the data from the datagrid row to my 2nd form. What I want to do now is to have the edited data from my 2nd form to my main form (in the datagrid). How will I do this? I've been trying to solve this by myself but I just can't! Please somebody help me!
-
Aug 30th, 2004, 07:16 PM
#19
Lively Member
anyone? please...i've been working on this for a couple of days now...but still to no avail! hope someone could show me how to do this.
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
|