VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Click event on Datagrid Posted by Mokone on 29 Jan 2009 at 12:14 AM
Hi all,
I have a datagrid that display the result of my query (EmployeeId and EmployeeName) and now I want to click on a datagrid row to get the EmployeeId to the next form.

Your help will be appreciated.
Report
Re: Click event on Datagrid Posted by jaakinye on 1 Feb 2009 at 5:02 PM
Please be specific
What order form do you mean?
Report
Re: Click event on Datagrid Posted by Mokone on 2 Feb 2009 at 12:00 AM
Hi,
I have two forms: frmMain and frmDisplay. I have datagrid on the frmMain that display the results of a query. Now what I want is to click on one of the rows of datagrid and call frmDiplay with the EmployeeId of the row clicked on frmMain. what I basically need is to click datagrid on frmMain and call frmDisplay to display the EmployeeId.
Report
Re: Click event on Datagrid Posted by seancampbell on 5 Feb 2009 at 6:47 AM
I am not sure if you want to have a new instance of frmDisplay for each time you click on that datagrid or if you want the same to change. I am going to assume you want the same to change so here is one method: (there are other equally correct solutions)

On your main form, declare a global variable:
 Dim fDisp as frmDisplay 


On your frmDisplay, you need a Public Sub or Public Function that you can pass the value you want to display. I don't know anything about your program, so here is an example of what it would look like:
Public Sub displayValue(ByVal Str as String)
  Me.TextBox1.Text = Str
End Sub


On you main form's datagrid's click event, you have to determine if frmDisplay is open, and pass the value to it in either case... Here is an example of what that would look like. You might have a question about a command I am using, I explain it below
If Not isNothing(fDisp) AndAlso Not isDisposed(fDisp)
  'fDisp is currently open
  If DataGrid1.SelectedIndicies(0) >= 0 Then
    fDisp.displayValue(DataGrid1.Item(DataGrid1.SelectedIndicies(0)))
    fDisp.Show()
  End If
Else
  'fDisp has either been closed, or never openned
  If DataGrid1.SelectedIndicies(0) >= 0 Then
    fDisp = new frmDisplay
    fDisp.Show()
    fDisp.displayValue(DataGrid1.Item(DataGrid1.SelectedIndicies(0)))
  End If
End If


AndAlso and OrElse are called Circut Logic. When you use And and Or in If statements, it evaluates ALL of the cases AT ONCE. When you use AndAlso and OrElse, it checks each case individually and stops evaluating as soon as a condition is fulfilled. This way, you can avoid Null reference errors, and use only one if statement instead of embedded if's.

Search for more info on AndAlso and OrElse if you still don't understand them. Hope I helped!
Report
Re: Click event on Datagrid Posted by Mokone on 9 Feb 2009 at 4:13 AM
Hi,
Thank you so much. I don't know what I would without you guys. You guys are really helping and inspiring us "the bigginers programmers".

Report
Re: Click event on Datagrid Posted by seancampbell on 11 Feb 2009 at 8:07 AM
No problem, we're here to help if we can. Kinda wish there was a tad bigger of a community solving VB.Net issues, but this works.

-Sean C



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.