Solved

DataGrid in .Net (Select a Row)

Posted on 2002-04-06
2
255 Views
Last Modified: 2010-05-02
I have VS .Net and am working with VB .Net.  I have a DataGrid on my form where I selected a pre-created style for it and set it to read-only.  What I want to do is have it only allow for a row to be selected, not individual cells.  I do not want the user to be able to select a cell, or multiple rows, just one row at a time.  I also need the ability to get DoubleClick to work like it works with the FlexGrid control back in VB6 (i.e. you can double-click on any cell and it will register a double-click event, with the DataGrid you have to double-click on the far left side of the control for it to register).  The code that I'm using to populate the DataGrid is below:

        Dim Adapter As OleDbDataAdapter
        Dim ds As DataSet
        Dim Sql As String

        'Perform the search
        Sql = "SELECT * FROM Customers WHERE FirstName LIKE '" & txtFirstName.Text & "%' AND LastName LIKE '" & txtLastName.Text & "%'"
        Adapter = New OleDbDataAdapter(Sql, cn)
        ds = New DataSet()
        Adapter.Fill(ds, "Customers")

        'Load the results into the datagrid
        Try
            grdResults.SetDataBinding(ds, "Customers")
        Catch ex As Exception
            'Don't worry about a blank dataset
        End Try

This works fine to load the results in, but right now the best I can do toward what I want is to set the DataGrid ("grdResults") to ReadOnly and then have a button on the form that checks "grdResults.CurrentRowIndex()" to determine what has been selected.  Double-clicking doesn't work, and I can't get it to select the entire row when a cell is clicked on.

I am up for suggestions on other controls to use (as long as they come with VS .Net Enterprise Edition).  I would prefer to use a .Net Framework component over a COM control. Any help is appreciated.
0
Comment
Question by:Egore
[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
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 150 total points
ID: 6924030
0
 
LVL 3

Author Comment

by:Egore
ID: 6926104
Those links worked like a charm.  Thank you!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

617 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