Solved

double click datagrid row to select row items

Posted on 2004-09-01
15
61,144 Views
Last Modified: 2011-08-18
how can i display the datagrid row items in to textboxes when double clicked on that row.
0
Comment
Question by:angireddy
15 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 125 total points
ID: 11953950
Something like this

    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        Dim pt As System.Drawing.Point = DataGrid1.PointToClient(Cursor.Position)

        Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.RowHeader Then
            TextBox1.Text = CType(DataSet11.Tables(0).Rows(hti.Row).Item("yourcolumn"), String)
        End If

    End Sub
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11953960
This will copy when you double click on the rowheader
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 11953964
this'll get you started...what this code does, is sends the double-clicked cell value to the textbox.

youll want to use a for loop and loop through the number of rows you have in order to get them all

    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        Me.TextBox1.Text = Me.DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)
    End Sub

~b
0
 

Author Comment

by:angireddy
ID: 11954218
thank you, wants to know how you can make the datagrid non editable.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11961835
There are several ways

datagrid1.readonly = true or

adjust the underlaying dataview

datagrid1.datasource = yourdataview
yourdataview.Allownew = false
yourdataview.Allowedit = false
yourdataview.Allowdelete = false

here you can see that is full customizable

you can allow edit but not delete and add or just allow add and delete but not edit etc...





0
 

Author Comment

by:angireddy
ID: 11962979
How to add menu when we right click on the datagrid, and the menu should be linked to the row of the datagrid
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11963037
This sounds like a complete new question. The rule here at EE is that you have to open a new question.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:angireddy
ID: 11963065
sure i will add this as a new question, thank you and sorry
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11963072
No problem.
0
 

Author Comment

by:angireddy
ID: 11972749
Hi RonaldBiemans,

The code you gave me worked well for some time, then started to give problems. The if statement "if hti.type = Datagrid.hitTestType.rowheader" is always false and the rowheader is showing as constant and the value is 4. Please let me know what I can do to correct the problem.

Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        Dim pt As System.Drawing.Point = DataGrid1.PointToClient(Cursor.Position)

        Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)
        If hti.Type = DataGrid.HitTestType.RowHeader Then
            TextBox1.Text = CType(DataSet11.Tables(0).Rows(hti.Row).Item("yourcolumn"), String)
        End If

    End Sub
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11972948
Well, the rowheader is always 4 because it is a constant, the problem lies with the hti.type which is somehow never 4.

Have you change something else in the datagrid, because a programs behaviour doesn't just change by itself so you must have changed something that has influenced this behaviour
0
 
LVL 2

Expert Comment

by:GohdanTheMoblin
ID: 12151637
The DataGrid's double-click event is tricky.  The DoubleClick event is only fired if you click on some portion of the DataGrid control that does not have a cell.  Otherwise, the first click is caught by the DataGrid and activates the cell, and the second click is caught by the cell.

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q869q
The above link (the anchor isn't working right in Firefox, it is item 5.46 on the page) has a project that properly catches a double-click in a DataGrid cell.  From within the double-click function, you can use the DataGrid.CurrentRowIndex function to figure out what row was clicked on, and use the DataGrid.Item property to fetch whatever values from the row you want.
0
 

Author Comment

by:angireddy
ID: 12152618
thank you
0
 

Expert Comment

by:BMcKD
ID: 12881844
Alternatively, you can disable the check boxes within the Datagrid, then the doubleclick is passed to the container.

Dim ctl As Control
For Each ctl In dgridMain.Controls
Dim gd As new System.Windows.Forms.DataGridTextBox
If ctl.GetType Is gd.GetType Then
ctl.Enabled = False
End If
Next

The grid will then respond to a double click in cells as well as the row header.

Solution coutesy -Banmere
0
 
LVL 1

Expert Comment

by:matthewsampson
ID: 13111477
Hi Guys,

I've been following this so far and it's all working great, so many thanks for posting it all. I'm quite new to all this so it's really helpful to read all the responses.

The problem I have is once I've edited the data in the textboxes, How do you get the data to go back into the datagrid?

Any help would be great.

Many Thanks


Matt Sampson
--------------------
Anglia University, Cambridge
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET HttpWebRequest 12 57
Visual Studio editor? 1 38
LINQ - C# to VB convertion 12 46
Visual Studio 2013 Shortcut (VB) 4 34
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now