views:

24

answers:

1

I have a datagridview in a winform that displays the content of a datatable which holds data recieved from my DB.

One column contains the urls of different sites. I'd like to turn all the site urls into links e.g:

from : htttp://stackoverflow.com

to : http://stackoverflow.com

I think I found what I need in http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewlinkcolumn.aspx but have no idea how to implement it in my code.

Thanks Asaf

private void loadGRD()
{
    string qry = "";
    qry = "Select top 10000 companyName,webSite from jobDB.dbo.companiesAll ";

    frmMainJobSearch a = (frmMainJobSearch)mainParent;
    DataTable dt = new DataTable();
    dt =a.connDB.userQuery(qry); // getting a table with one column of the databases names
    grdHashamaLst.DataSource = dt;
}
A: 

Where you're defining your columns, you need something like this:

DataGridViewLinkColumn links = new DataGridViewLinkColumn();

links.UseColumnTextForLinkValue = true;
links.HeaderText = "Links"; //put the header text you want here
links.DataPropertyName = "webSite"; //This is from your query
links.ActiveLinkColor = Color.White;
links.LinkBehavior = LinkBehavior.SystemDefault;
links.LinkColor = Color.Blue;
links.TrackVisitedState = true;
links.VisitedLinkColor = Color.YellowGreen;

grdHashamaLst.Columns.Add(links);
msergeant
That's exactly the place I got lost: I do not define the columns...The code I wrote above does all the work for me (except the part you gave me).My problem is how to merge those codes.
Asaf
Your columns are most likely defined inside the InitializeComponent function (in form.designer.cs). That's where everything that you've set up in the designer gets put. You'll want to remove the old column from the designer and put this code after your call to InitializeComponent.
msergeant