I want to make a column in my RadGridView clickable, such that clicking on a cell in a particular column opens another view with details for that row. I tried adding a button to the column, but I can't get the button to show the text from the actual column. I've got my RadGridView bound to a System.Data.DataTable, and am defining the column as follows:
<
telerik:GridViewDataColumn
Header
=
"Action"
DataMemberBinding
=
"{Binding commandName}"
UniqueName
=
"actionButton"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
telerik:RadButton
Content
=
"{Binding commandName}"
Click
=
"ActionClicked"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
...but the button shows up as a skinny horizontal line with no text. It shows up as expected if I hard code the button content.
private void gridView_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e) { double width = 0; foreach (var col in gridView.Columns) { // None of these gives me the desired value //width += col.ActualWidth; //width += col.Width.DisplayValue; //width += col.Width.Value; } gridView.Width = width; }
Hi,
In my project, I have to create GridViewDataColumn for my RadGridView dynamically. When I finish creating my columns, I load data into my grid but the sort, filter and the grouping doesn't work :( I cannot see my filter button and if I try to drag a column header into the group panel, nothing happen.
Here is in my grid:
<telerik:RadGridView x:Name="radGridViewList" Margin="5 0 5 5" Visibility="Visible" RowDetailsVisibilityMode="Collapsed" FrozenColumnCount="1"
RowIndicatorVisibility="Collapsed" IsReadOnly="True" AutoGenerateColumns="False" CanUserFreezeColumns="False" Grid.Row="3"
CanUserResizeColumns="True" ShowColumnFooters="True" ShowGroupFooters="True" SelectionMode="Extended" IsSynchronizedWithCurrentItem="True" />
here is the code-behind:
static public void SetColumns(RadGridView pGrid, ColumnDescriptor[] pColumnNames)
{
if (pColumnNames != null)
{
SortedList<int, GroupDescriptor> grouping = new SortedList<int, GroupDescriptor>();
for (int iColumnIndex = 0; iColumnIndex < pColumnNames.Length; iColumnIndex++)
{
ColumnDescriptor oneName = pColumnNames[iColumnIndex];
Telerik.Windows.Controls.GridViewDataColumn oneColumn = new Telerik.Windows.Controls.GridViewDataColumn();
oneColumn.Header = oneName.ColumnName;
//Apply proper column display format.
switch (oneName.Format.ToUpper())
{
case "$":
oneColumn.DataFormatString = "C2";
break;
case "D":
oneColumn.DataFormatString = "yyyy'-'MM'-'dd";
break;
case "H":
oneColumn.DataFormatString = "HH':'mm";
break;
case "DH":
oneColumn.DataFormatString = "yyyy'-'MM'-'dd' 'HH':'mm";
break;
}
oneColumn.Width = new GridViewLength(1, GridViewLengthUnitType.Star);
oneColumn.ShowFilterButton = true;
oneColumn.IsSortable = true;
oneColumn.IsFilterable = true;
oneColumn.IsGroupable = true;
oneColumn.DataMemberBinding = new Binding(string.Format("ElementCells[{0:D}]", iColumnIndex));
oneColumn.TextAlignment = (TextAlignment)oneName.TextAlignment;
oneColumn.HeaderTextAlignment = (TextAlignment)oneName.TextAlignment;
//Create proper aggregate functions.
if (oneName.Agregation != AgregationFunction.None)
{
AddAggregateToColumns(ref oneColumn, oneName, string.Format("ElementCells[{0:D}]", iColumnIndex));
}
//Grouping field.
if (oneName.GroupingPosition != 0)
{
grouping.Add(Math.Abs(oneName.GroupingPosition),
new GroupDescriptor { DisplayContent = oneName.ColumnName, Member = string.Format("ElementCells[{0:D}]", iColumnIndex),
SortDirection = oneName.GroupingPosition > 0 ? ListSortDirection.Ascending : ListSortDirection.Descending});
}
//Add the column to the grid.
pGrid.Columns.Add(oneColumn);
}
//If grouping exist, add it to the grid.
if (grouping.Count != 0)
{
foreach (KeyValuePair<int, GroupDescriptor> oneGrouping in grouping)
{
pGrid.GroupDescriptors.Add(oneGrouping.Value);
}
}
}
}
Thank's