Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i have one question



i have one datagrid and the content of that datagrid are name ,address,phone email and url. the value of tht datagrid are as follows:
name address phone email url
xyz india 123456789 test@test.com https://www.google.com



now my question is when i click on url(https://www.google.com),that url should change its colour(Hyperlink) so that user can easily identify that can be fetch to mozilla or IE

and the code to fetch that URl is:
C#
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        if(e.ColumnIndex == 5) //According to my question
           {
             System.Diagnostics.Process.Start(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());
           }
        }



plz help me out
Posted
Updated 7-Aug-11 22:31pm
v3

 
Share this answer
 
Comments
Prerak Patel 8-Aug-11 4:40am    
Dude, you have posted wrong link. DataGridViewComboBoxColumn instead of DataGridViewLinkColumn. Change it.
Hello,

how do you fill your DataGridView?

Somethink like this:
DatagridView1.DataSource = [$YourDataSourceObject]


or like this:
DataGridView1.Rows.Add("Name", "Adress", "Phone", "EMail", "URL");
 
Share this answer
 
Comments
rbnsubedi01 8-Aug-11 4:47am    
i fill my Datagrid like this:
string querry = "select name as [Name],address as [Address],phone as [Phone],email as [Email],url as [URL] from record";

SqlConnection connect = new SqlConnection(str);//str is my connection string
connect.Open();
SqlCommand cmd = new SqlCommand(querry, connect);
SqlDataAdapter abc = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
abc.Fill(ds);
bindsrc.DataSource = ds.Tables[0];
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
dataGridView_1.DataSource = bindsrc;



//public BindingSource bindsrc = new BindingSource();
In the item template just place a hyperlink control in the gridview for that particular column which you want to display as a web address.

and bind the datasource to gridview as usual.
 
Share this answer
 
v2
Hello,

First you must create your Columns in the DataGridView like this:
C#
DataGridViewTextBoxColumn cName = new DataGridViewTextBoxColumn();
           cName.HeaderText = "Name";

            DataGridViewTextBoxColumn cAdress = new DataGridViewTextBoxColumn();
            cAdress.HeaderText = "Adress";

            DataGridViewTextBoxColumn cPhone = new DataGridViewTextBoxColumn();
            cPhone.HeaderText = "Phone";

            DataGridViewTextBoxColumn cEMail = new DataGridViewTextBoxColumn();
            cEMail.HeaderText = "EMail";

            DataGridViewLinkColumn cURL = new DataGridViewLinkColumn();
            cURL.HeaderText = "URL";

            dataGridView1.Columns.Add(cName);
            dataGridView1.Columns.Add(cAdress);
            dataGridView1.Columns.Add(cPhone);
            dataGridView1.Columns.Add(cEMail);
            dataGridView1.Columns.Add(cURL);

You can also create your Columns in the Designer.

Next step you read your DB into a DatSet and read each record of the DataSet.
You can add the Values like this:
C#
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
    dataGridView1.Rows.Add(ds.Tables[0].Rows[i]["Name"].ToString(),
        ds.Tables[0].Rows[i]["Adress"].ToString(),
        ds.Tables[0].Rows[i]["Phone"].ToString(),
        ds.Tables[0].Rows[i]["EMail"].ToString(),
        ds.Tables[0].Rows[i]["URL"].ToString());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900