问题
I have a UltraGridCell with style equal to Infragistics.Win.UltraWinGrid.ColumnStyle.URL and add my own handler to UltraGrid.MouseClick so that I can open a new tab if the URL columns is clicked
Nothing is wrong if the URL column is of the value "ABCDE". It looks like a URL link in the cell with underline and blue color (turns purple after click). It just like a URL link in the browser.
The issue is that if the content is of the value like "ABC:DE". It turns out it complains that there is an undefined protocol is calling. Just like you enter "ABC://DE" at the IE URL bar.
After checking in the debug mode, it looks like that this should be called by UltraGrid internally. Hence, my question is: Is there any way for me to disable this default behaviour?
Any help is highly appreciated.
回答1:
When you set the column style to Infragistics.Win.UltraWinGrid.ColumnStyle.URL
the editor of the column becomes Infragistics.Win.FormattedLinkLabel.FormattedLinkEditor
. This editor has LinkClicked
event. In the event handler you can get OpenLink
property of the event argument and set it to false
. This will suppress link opening. To do so, first get the editor in the InitializeLayout
event:
private void UltraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
// get the column you will set up
var column = e.Layout.Bands[YOUR_BAND_INDEX].Columns[YOUR_COLUMN_INDEX];
// set the style of the column (you already did this)
column.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.URL;
// get the editor after set the column style and handle LinkClicked event
var editor = column.Editor as FormattedLinkEditor;
editor.LinkClicked += this.Editor_LinkClicked;
}
Then in LinkClicked
event stop link opening:
private void Editor_LinkClicked(object sender, Infragistics.Win.FormattedLinkLabel.LinkClickedEventArgs e)
{
e.OpenLink = false;
}
来源:https://stackoverflow.com/questions/60929523/undefined-protocol-in-the-url-cell