?
Solved

Is there a way to get the events arguements of a dataGridView so I can call one of its eventhandlers?

Posted on 2008-06-12
7
Medium Priority
?
167 Views
Last Modified: 2013-11-26
Hello,

I have a dataGridView which a few things happen when one of the rows is clicked.  I handle this using the "CellClicked" event.  The cell clicked event requires two parameters, the first is the sender as an object (which I can cast my dataGridView to), and the second is a System.Windows.Forms.DataGridViewCellEventArgs.  Is there any way I can get or create the last  argument so I can call the event handler?  I have actually wanted to do this several times, but I have never figured out how to get ahold of the arguements.  

Thanks,

Rob
0
Comment
Question by:kidl33t
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 21771166
You can set the last paramater to Nothing
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21771178
Probably it's better to show us your code!
0
 

Author Comment

by:kidl33t
ID: 21771366
jpaulino:
I am looking to do this because I am creating a couple of buttons intended to scroll up and down the rows of a fairly customised datagridview.  The trouble is that if you go:

DGV.Rows(DGV.currentRow.Index + 1).Selected = True    '(assumg DGV is some dataGridView)

Visual basic does indeed mark that row as selected.  The problem is, it doesn't update the .currentRow property.  Eg if the currentRow was 0, the above code selects row 1, but the currentRow property still says 0.  The currentRow property is also ready only, so I can't update it either.  I need it to be updated however, because several other things depend on the currently selected row.

That's why I wanted to fire a CellClick event on the DGV, so it would do whatever it has to do internally to update the currentRow field.  

Does this make sense?
0
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 

Author Comment

by:kidl33t
ID: 21771399
Whoops, the code I am working is:


    Private Sub PhotoNextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhotoNextButton.Click
        If Me.PhotosSelectDGV.CurrentRow.Index <= Me.PhotosSelectDGV.RowCount - 2 Then ' Make sure it doesn't try and run past the end of the rows
            Me.PhotosSelectDGV.Rows(Me.PhotosSelectDGV.CurrentRow.Index + 1).Selected = True
            Me.PhotosFullSizePB.Image = Me.getImageByID(Me.PhotosSelectDGV.CurrentRow.Cells("image_id").Value, True)
        End If
    End Sub
 
'And if you need it, get image by id is:
 
    'Returns the image from the DB, also resizes it to Me.PhotosFullSizePB dimensions
    Private Function getImageByID(ByVal id As Integer, ByVal resize As Boolean) As System.Drawing.Image
        Dim image_id As New SqlParameter("@image_id", id)
        Dim query As String = "EXEC dbo.select_image_by_id @image_id"
        Dim connection As SqlConnection = New SqlConnection(Me.connectionString)
        Dim command As New SqlCommand(query, connection)
        Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
        command.Parameters.Add(image_id)
        If Me.masterDS.Tables("currentFullImage") IsNot Nothing Then Me.masterDS.Tables("currentFullImage").Clear()
        adapter.Fill(Me.masterDS, "currentFullImage")
        Dim buffer As Byte()
        buffer = masterDS.Tables("currentFullImage").Rows(0).Item("binary")
        Dim ms As New IO.MemoryStream(buffer)
        Dim img As System.Drawing.Image
        img = System.Drawing.Image.FromStream(ms)
        If resize = False Then Return img
        If img.Height > Me.PhotosFullSizePB.Height And img.Width > Me.PhotosFullSizePB.Width Then
            Dim percTooTall As Decimal = img.Height / Me.PhotosFullSizePB.Height
            Dim percTooWide As Decimal = img.Width / Me.PhotosFullSizePB.Width
            If percTooTall >= percTooWide Then
                img = Me.GenerateThumbnail(img, CType(((Me.PhotosFullSizePB.Height / img.Height) * 100), Integer))
            Else
                img = Me.GenerateThumbnail(img, CType(((Me.PhotosFullSizePB.Width / img.Width) * 100), Integer))
            End If
        ElseIf img.Height > Me.PhotosFullSizePB.Height Then
            img = Me.GenerateThumbnail(img, CType(((Me.PhotosFullSizePB.Height / img.Height) * 100), Integer))
        ElseIf img.Width > Me.PhotosFullSizePB.Width Then
            img = Me.GenerateThumbnail(img, CType(((Me.PhotosFullSizePB.Width / img.Width) * 100), Integer))
        End If
        Return img
    End Function

Open in new window

0
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 21771553
You don't need to do that.

Try this way:


Dim myRowNumber As Integer = DGV.currentRow.Index + 1
Me.DGV.CurrentCell = Me.DGV(1, myRowNumber)
Me.DGV.Rows(myRowNumber).Selected = True    

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21771569
I didn't sow your last post. Just try it changing the name of the DGV to PhotosSelectDGV
0
 

Author Closing Comment

by:kidl33t
ID: 31466608
Thanks man.  I didn't realize when I asked the question, my issue was actually that if I select a row programatically with the .selected=true that it doesn't update the currentrow.  I actually figured out the currentCell thing shortly after I posted this, but I think you should get the points for helping.  Cheers!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question