Hi,
I want some columns show hyperlink, and I found GridViewHyperlinkColumn and GridViewDataColumn in RadGridView.
My question is how to include them into RadGridView dynamically base on custom logic?
for example, when the grid load first time only col1, col3 and col 5 need to display as hyperlink, but when same grid load second time, maybe col2, col5 and col8 need to display hyperlink, not col1 and col3.
Thanks.
I want some columns show hyperlink, and I found GridViewHyperlinkColumn and GridViewDataColumn in RadGridView.
My question is how to include them into RadGridView dynamically base on custom logic?
for example, when the grid load first time only col1, col3 and col 5 need to display as hyperlink, but when same grid load second time, maybe col2, col5 and col8 need to display hyperlink, not col1 and col3.
Thanks.
7 Answers, 1 is accepted
0
Hi tzuhsun,
Vanya Pavlova
the Telerik team
Indeed you may change the DisplayIndex of each column, which allows you to determine which column appears as first to the left. If your columns are auto-generated you may handle the AutoGeneratingColumn event of RadGridView and observe the column properties there.
Please let me know how this works for you.
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
tzuhsun
Top achievements
Rank 1
answered on 03 May 2011, 10:44 AM
Hi Vanya,
Yes the columns are auto-generated, from the link you gave notices that is code to disable auto-generate column for particular column, I think that is what I want.
I try myself here to replace the disabled column with Hyperlink column, below is my code:
Yes the columns are auto-generated, from the link you gave notices that is code to disable auto-generate column for particular column, I think that is what I want.
I try myself here to replace the disabled column with Hyperlink column, below is my code:
// Inside AutoGeneratingColumn event...
if
(e.Column.UniqueName ==
"Duration"
|| e.Column.UniqueName ==
"No"
)
{
Telerik.Windows.Controls.GridViewHyperlinkColumn linkColumn =
new
Telerik.Windows.Controls.GridViewHyperlinkColumn();
linkColumn.ContentBinding =
new
Binding(@
"c:\papapa"
);
linkColumn.DataMemberBinding = (e.Column
as
Telerik.Windows.Controls.GridViewBoundColumnBase).DataMemberBinding;
linkColumn.Header = e.Column.Header;
linkColumn.UniqueName = e.Column.UniqueName;
linkColumn.DisplayIndex = e.Column.DisplayIndex;
linkColumn.IsFilterable = e.Column.IsFilterable;
linkColumn.IsEnabled = e.Column.IsEnabled;
linkColumn.IsReadOnly =
true
;
e.Column = linkColumn;
}
it is not working, may I know which parts go wrong here?
Another question is if I able to replace column with hyperlink column, would the layout setting recognizes the new hyperlink column?
Many thanks.
0
Gaurang
Top achievements
Rank 1
answered on 10 Aug 2011, 02:47 PM
Hi,
I want to set hyperlink on my Silverlight custome Gridview but when I bind the data it gives me Display IndexOutofRang Account error.
I set autogenerate propery true and bind the perticular field in Autogerate event. But my gridview.columns.count is 14 before I start binding data because I want to display only 14 columns out of 80 columns.
How to set Display index or how to manage it.
Your reply is helpful for me to resolved this issue.
Thanks,
Gaurang
I want to set hyperlink on my Silverlight custome Gridview but when I bind the data it gives me Display IndexOutofRang Account error.
I set autogenerate propery true and bind the perticular field in Autogerate event. But my gridview.columns.count is 14 before I start binding data because I want to display only 14 columns out of 80 columns.
How to set Display index or how to manage it.
Your reply is helpful for me to resolved this issue.
Thanks,
Gaurang
0
tzuhsun
Top achievements
Rank 1
answered on 11 Aug 2011, 07:19 AM
Hi Gaurang,
I actually move to another method and not using the grid hyperlink column, therefore I not play with the DisplayIndex mentioned previously.
Not sure why you hit the error, but if I want to display 14 cols out of 80 cols, what I will do is inside grid's
To hide the column you may try this:
e.Column.isVisible = false;
I actually move to another method and not using the grid hyperlink column, therefore I not play with the DisplayIndex mentioned previously.
Not sure why you hit the error, but if I want to display 14 cols out of 80 cols, what I will do is inside grid's
AutoGeneratingColumn
event, filter the 14 cols out and hide the rest.To hide the column you may try this:
e.Column.isVisible = false;
0
Gaurang
Top achievements
Rank 1
answered on 11 Aug 2011, 09:21 AM
HI Tzuhsun,
Thaks for your reply.
Still I am getting same error. I do not know how it comes.
I also try to comment some code (above first 3 line of code) and then try but still it gives me same error "Display IndexOutOfRange Account".
Thaks for your reply.
Still I am getting same error. I do not know how it comes.
gv.Columns.AddRange(new Controller().GridViewColumns);
gv.Columns.Remove(gv.Columns[Language.Activity.LBLTYPE.ToString()]);
GridViewHeaderMenu.SetIsEnabled(gv, true); // set the header menu when user right click it will dispaly list of grid header list
----------------------------------------------------------------------------------------------------------------------
private void gv_Loaded(object sender, RoutedEventArgs e)
{
gv.Columns.Insert(0, GridViewRowDetailsToggleColumn.GetColumn());
gv.RowDetailsTemplate = Application.Current.Resources["RowDetailTemplate"] as DataTemplate;
gv.Loaded -= gv_Loaded;
}
------------------------------------------------------------------------------------------------------------------
private void gvCalls_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
if (e.Column.UniqueName == "xyz" || e.Column.UniqueName == "rqr")
{
Telerik.Windows.Controls.GridViewHyperlinkColumn linkColumn = new Telerik.Windows.Controls.GridViewHyperlinkColumn();
linkColumn.ContentBinding = new System.Windows.Data.Binding(@"c:\papapa"); // how to set when user click open new form
linkColumn.DataMemberBinding = (e.Column as Telerik.Windows.Controls.GridViewBoundColumnBase).DataMemberBinding;
linkColumn.Header = e.Column.Header;
linkColumn.UniqueName = e.Column.UniqueName;
linkColumn.DisplayIndex = e.Column.DisplayIndex;
linkColumn.IsFilterable = e.Column.IsFilterable;
//linkColumn.IsEnabled = e.Column.IsEnabled;
linkColumn.IsReadOnly = true;
e.Column = linkColumn;
}
else if (e.Column.UniqueName == "abc"
|| e.Column.UniqueName == "Date"
|| e.Column.UniqueName == "123" )
{}
else
{
//e.Cancel = true;
e.Column.IsVisible = false;
}
}
I also try to comment some code (above first 3 line of code) and then try but still it gives me same error "Display IndexOutOfRange Account".
0
Gaurang
Top achievements
Rank 1
answered on 11 Aug 2011, 11:36 AM
Hi,
Now my problem is resolved.
I just set the
Now my problem is resolved.
I just set the
linkColumn.DisplayIndex = gv.Columns.count;
And it is working perfect.
Thanks,
Gaurnag
0
Gaurang
Top achievements
Rank 1
answered on 11 Aug 2011, 02:14 PM
Hi,
Below is my code for Hyperlink
<
Grid.Resources
>
<
telerikcontrols:GridViewHyperlinkColumn:Name
=
"GridViewHyperLinkColumnTemplet"
>
<
telerikcontrols:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
HyperlinkButton
x:Name
=
"HyperLink"
Click
=
"HyperLink_Click"
HorizontalContentAlignment
=
"Center"
VerticalContentAlignment
=
"Center"
/>
</
DataTemplate
>
</
telerikcontrols:GridViewColumn.CellTemplate
>
</
telerikcontrols:GridViewHyperlinkColumn
>
</
Grid.Resources
>
---------------------------------------------------------------------------------
private void gv_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
if (e.Column.UniqueName == "abc" || e.Column.UniqueName == "xyz")
{
Telerik.Windows.Controls.GridViewHyperlinkColumn linkColumn = new Telerik.Windows.Controls.GridViewHyperlinkColumn();
linkColumn.CellTemplate = GridViewHyperLinkColumnTemplet.CellTemplate;
//linkColumn.ContentBinding = new ystem.Windows.Data.Binding(@"c:\papapa");
linkColumn.DataMemberBinding = (e.Column as Telerik.Windows.Controls.GridViewBoundColumnBase).DataMemberBinding;
linkColumn.ContentBinding = new System.Windows.Data.Binding();
linkColumn.Header = e.Column.Header;
if (e.Column.UniqueName == "xyz")
{
linkColumn.UniqueName = "xyz";
}
if (e.Column.UniqueName == "abc")
{
linkColumn.UniqueName = "abc";
}
linkColumn.DisplayIndex = gv.Columns.Count;
linkColumn.IsFilterable = e.Column.IsFilterable;
linkColumn.IsEnabled = e.Column.IsEnabled;
//linkColumn.IsReadOnly = true;
e.Column = linkColumn;
}
else
{
e.Cancel = true;
}
}
private void HyperLink_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(e.ToString());
}
but Hyperlink_Click event not raise insted of that I got excepation. Like "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
Now anybody tell me how to bind template runtime in custome grid.
Thanks,
Gaurang