Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

double click datagrid row to select row items

Posted on 2004-09-01
15
Medium Priority
?
61,161 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
[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
15 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 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