How to display a column of sites links in a winform Datagridview which datasource is a Datatable containing data from DB
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/librar开发者_JAVA技巧y/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;
}
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);
精彩评论