DataGridView Link Cell


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: DataGridView Link Cell

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    9

    DataGridView Link Cell

    I'm working in VS2005, and have a DataGridView that draws from a datasource. Is there a way to change a column to be a link style column after the DataGridView populates? Here's how I populate it:


    Code:
    DataSet ds = new DataSet();
    dgvShipmentHistory.DataSource = null;
    SqlDataAdapter da = new SqlDataAdapter(mySQLClass.Query, mySQLClass.SqlCon);
    da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
    da.Fill(ds, "ShipmentHistory");
    dgvShipmentHistory.DataSource = ds.Tables[0];
    dgvShipmentHistory.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
    I want to be able to change one of the columns to be a link type column so that users can click the hyperlink and I can throw up a page.

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Why can't you define the hyperlink column at design-time?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jun 2007
    Posts
    9
    The datagrid is bound at runtime. Some of the columns in the grid may vary from time to time based on the fields in the database.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this:
    Code:
    Protected Sub Page_Load(ByVal sender As Object, _ 
        ByVal e As System.EventArgs) Handles Me.Load
        ' Remove existing first column
        dgvShipmentHistory.Columns.RemoveAt(0)
        ' Create new hyperlink field
        Dim Link As New HyperLinkField()
        With Link
            .DataTextField = "ShipmenID"
            Dim Fields() As String = {"ShipmentID"}
            .DataNavigateUrlFields = Fields
            .DataNavigateUrlFormatString = "http://www.domain.com/ViewShipment.aspx?ID={0}"
            .HeaderText = "ShipmentID"
        End With
        ' Insert new hyperlink field as first column
        dgvShipmentHistory.Columns.Insert(0, Link)
    End Sub
    Last edited by Phil Weber; 07-12-2007 at 01:21 AM.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Feb 2012
    Posts
    2
    For display hyperlink in datagridview control in c#, get the help from following link. I hope it helpful for you

    http://www.mindstick.com/Articles/4d...taGridView%20C

Similar Threads

  1. Whitspace in datagridview cell
    By jcb1269 in forum .NET
    Replies: 1
    Last Post: 03-21-2007, 02:02 PM
  2. Color DataGridView cell on exception
    By jellyfish5000 in forum .NET
    Replies: 2
    Last Post: 03-01-2007, 09:29 AM
  3. DataGridView Returning Values from Cells
    By triley35 in forum .NET
    Replies: 1
    Last Post: 07-08-2006, 01:34 AM
  4. Get cell value on click of link button
    By Rathi in forum ASP.NET
    Replies: 1
    Last Post: 06-05-2006, 05:46 AM
  5. Replies: 0
    Last Post: 12-06-2002, 12:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center