|
-
Jul 2nd, 2007, 06:06 PM
#1
Thread Starter
PowerPoster
Vb.Net 2005 - Defining a DGV Column as LinkCell???
I am trying to define a column in a DataGridView as a LinkCell and I keep getting the following error:
"Value provided for cell template must of type 'Windows.System.Forms.DataGridViewTextBoxCell' or derive from it"
I've included my code:
Code:
Private Sub FormatGrid3()
Try
grd3.RowHeadersVisible = False
grd3.Columns(0).Width = 100
grd3.Columns(0).HeaderText = "Request ID"
grd3.Columns(1).Width = 140
grd3.Columns(1).CellTemplate = New DataGridViewLinkCell
grd3.Columns(1).HeaderText = "Image Name"
grd3.Columns(2).Width = 430
grd3.Columns(2).HeaderText = "File Path"
Catch ex As Exception
ErrorHandler(strModule, strProcedure, Msg)
End Try
End Sub
-
Jul 2nd, 2007, 08:46 PM
#2
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
You can't change the type of a column once it's been created. If you are relying on the grid to create the columns for you then it's going to create text box columns in most cases as that's the default type for most data types. If you want a column of hyperlinks then you'll have to create that column yourself, either in code or, more likely, in the designer. You set the column's DataPropertyName to specify that it should bind to a specific column in the data source.
-
Jul 3rd, 2007, 09:10 AM
#3
Thread Starter
PowerPoster
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
Ok,
I got it working...but when I click/doubleclick on the filename (linked cell)...nothing happens. I thought that because it is defined as a LinkCell that it would automatically associate an application to open the link.
Last edited by blakemckenna; Jul 3rd, 2007 at 09:27 AM.
Blake
-
Jul 4th, 2007, 04:22 AM
#4
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
If you had read the MSDN documentation for the DataGridViewLinkColumn class you would already have your answer.
-
Jul 5th, 2007, 10:08 AM
#5
Thread Starter
PowerPoster
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
I did a search using VS Help and all I got was the following:
Code:
Private Sub AddLinkColumn()
Dim links As New DataGridViewLinkColumn()
With links
.HeaderText = ColumnName.ReportsTo.ToString()
.DataPropertyName = ColumnName.ReportsTo.ToString()
.ActiveLinkColor = Color.White
.LinkBehavior = LinkBehavior.SystemDefault
.LinkColor = Color.Blue
.TrackVisitedState = True
.VisitedLinkColor = Color.YellowGreen
End With
DataGridView1.Columns.Add(links)
End Sub
This doesn't help me do what I want?
-
Jul 6th, 2007, 01:20 AM
#6
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
Every class has at least two topics dedicated to it in the MSDN library: one an overview of the class and the other a list of members. Had you read the class overview for the DataGridViewLinkColumn class you would have seen this:
To respond to user link clicks, handle the DataGridView.CellContentClick event. You can also use the DataGridView.CellClick event to respond to clicks anywhere in the cell.
-
Jul 12th, 2007, 04:25 PM
#7
Thread Starter
PowerPoster
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
If a user clicks on a file name within a LinkCell....will the appropriate program open the file or does that need to be programmed accordingly?
Thanks,
-
Jul 12th, 2007, 05:52 PM
#8
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
will the appropriate program open the file
You've already said that when you click a link nothing happens.
does that need to be programmed accordingly
The documentation I quoted says that you're supposed to handle the CellContentClick event of the grid. Why do you usually handle events? So that you can execute some code when something happens. In this case that means performing the desired action when the user clicks the content in your link cells.
-
Jul 12th, 2007, 06:33 PM
#9
Hyperactive Member
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
you have to pocess the action in event, although you can define a 'LinkCell'. just like in RichText, you can enable LinkText, but you have to process it in LinkClicked event.
you can use default browser to open the link:
Try
System.Diagnostics.Process.Start(e.LinkText)
Catch ex As Exception
MsgBox("Can not open " & e.LinkText & " using default browser!", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly)
End Try
bear
-
Jul 13th, 2007, 09:05 AM
#10
Thread Starter
PowerPoster
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
Thank you Flying Bear...that's exactly the answer I was looking for. I didn't think my question was that hard to understand. Some people just can't give a straight answer.
-
Jul 13th, 2007, 05:29 PM
#11
Thread Starter
PowerPoster
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
Bear,
To which object does the LinkClicked Event belong to?
Thanks,
-
Jul 13th, 2007, 09:49 PM
#12
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
You handle the CellClick event and test e.ColumnIndex to see it it's the link column. If it is, you do as Flying Bear have shown.
-
Jul 13th, 2007, 10:00 PM
#13
Re: Vb.Net 2005 - Defining a DGV Column as LinkCell???
I didn't think my answer was that hard to understand:
handle the CellContentClick event of the grid
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|