Re: Handling link clicks in a DataGridViewLinkColumn



Hi,

"lilfos" <dontsellthis@xxxxxxxxxxx> wrote in message
news:1165867419.804410.82680@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I feel like I'm missing something basic here, but I can't find anything
that answers my questions in MSDN or Google Groups. I have two link
columns in my DataGridView. I managed to bind them to columns in a
DataTable using the DataPropertyName property. All other columns are
bound manually. The cells look good, but they don't function properly
(well, at all). I can't get my click handler to figure out what link
was clicked.

The GUI design calls for one column to contain mailto links and one to
contain web page links. The mailtos should do the equivalent of
wrapping the email address displayed in the cell with the appropriate
<a> tag structure. Clicking it would launch a new message window from
the default email editor. The other column should show a page title in
each cell and handle the click by popping up a browser and loading the
desired URL.

Question 1: How do I handle the click for the link itself...not the
row, not the whole grid...just the link?? Everything I read says
something like, bind the column manually and use the cellclick event.

Yes, handle the DataGridView.CellContentClick and check if the column is one
of your link columns, eg. :

private void employeeDataGridView_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2) // 3th column is a linkcolumn
{
// access cell value, you could also access other cell values
Console.WriteLine( yourDataGridView[e.ColumnIndex, e.RowIndex].Value );

// or if you want access to the bound object
// yourDataGridView.Rows[e.RowIndex].DataBoundItem

// do something
}
}

To start the default browser or mail program you could use Process.Start
(System.Diagnostics), eg. :
Process.Start( "http://www.google.com"; );
Process.Start( "mailto:someon@..."; );

There is no such a thing as <a> tag in winforms.

HTH,
Greetings

Does this mean that I need to loop through every row in table, add a
cell to the link column, and add an event handler for that cell that
builds an <a> tag and performs the desired action? That would be
really inelegant.

Question 2: When using a DataGridViewLinkColumn, what are the
equivalent of the Text and NavigateURL properties? Do I have to build
a link control for each cell and then set that into the Value property
of the DataGridViewLinkCell?

Bonus Question: This DataGridView supports dragging (drag from, but not
drop to). The MouseDown event seems to prevent the CellClick event
from firing. Assuming I can work everything else out, can I bubble up
the click so that MouseDown will handle a MouseDown/hold whereas a full
click would fire the click event?

Like I said, I feel like I'm just not getting the
DataGridViewLinkColumn. Other than alter text appearance, it really
doesn't seem to do anything useful. What am I missing??

Thanks



.



Relevant Pages

  • Handling link clicks in a DataGridViewLinkColumn
    ... I feel like I'm missing something basic here, ... each cell and handle the click by popping up a browser and loading the ... This DataGridView supports dragging (drag from, ... The MouseDown event seems to prevent the CellClick event ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: DataGridView Enter Key
    ... ProcessDialogKey method in the DataGridView, that is where the Enter key was ... is that the DataGridView key events are not being raised, because the cell ... trap the Enter key when the current cell in edit mode. ... press the Enter key, the KeyDown, KeyPress and KeyUp events are raised in ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: DataGridRowView.ContextMenuStrip
    ... Erst in der richtigen Cell die rechte Maustaste. ... Wobei ich hier zum Testen ein DataGridView mit Standardeinstellungen ... der Code hat aber die vom Linksklick. ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: DataGridView, updating values and Resetbindings
    ... There is a form which contains nothing but a DataGridView, ... The values are there and if I select a cell, ... In case the resetBindings() call is correct, ... that each call automatically selects a cell, the old selection is ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • RE: IDataGridViewEditingControl validation
    ... from leaving the current cell if the entered value is not valid, ... subscribe the CellValidating event of the referenced DataGridView within ... // add a new property called Value, which is of type DateTime ... public DataGridView EditingControlDataGridView ...
    (microsoft.public.dotnet.framework.windowsforms.controls)