Telerik Forums
UI for WPF Forum
1 answer
345 views


I'm binding my GridView to a custom report class with records.   The `Report`class has a list of field types that is not known until runtime.  It exposes an array of `Record` objects.  The Record class derives from System::DynamicObject.  Binding an IEnumerable<Record> to GridView is pretty easy with the AutoGenerateColumns turned on.    (Note this code is C++/CLI but the client code that uses it is C#/WPF/XAML)

public ref class Record 
    : public DynamicObject
{
    int     m_row;
    Report^ m_rep;

public:
    Record(Report^ rep, int row);
#pragma region DynamicObject Overrides
    virtual bool TryGetMember(GetMemberBinder^ binder, [SRI::Out]Object^% obj) override;
    virtual bool TrySetMember(SetMemberBinder^ binder, Object^ value) override;
    virtual IEnumerable<String^>^ GetDynamicMemberNames () override;
    virtual bool TryGetIndex(GetIndexBinder^ binder, array<Object^>^ indices, [SRI::Out]Object^% result) override;
#pragma endregion 
    
    property Object^    default[int]  { Object^ get(int idx); }
    property Object^    default[String^] { Object^ get(String^ name); }
};

The problem is that when I bind it, this way, the values displayed just use the default `ToString()` method of each object.  That's not going to work.  I need to use DataTemplates, For example, I want any double value to use 3 decimal places. 


<tk:RadGridView.Resources>
    <DataTemplate x:Key="MyDoubleTemplate" DataType="{x:Type sys:Double}">
        <Label ContentStringFormat="{}{0:F3" Content="{Binding}"/>
    </DataTemplate>
</tk:RadGridView.Resources>


So I tried adding a handler for the `AutoGeneratingColumn` column event.  In the handler and explicitly specifying the `CellTemplate` to be used for each column.  (I named the templates in XAML and then loaded them directly via TryFindResource)

private void GridView_OnAutoGeneratingColumn(object? sender, GridViewAutoGeneratingColumnEventArgs e)
{
    if (e.Column is not GridViewDataColumn col)
        return;
    
    var name = col.DataMemberBinding.Path.Path;

    if (!TryGetField(name, out var field, out var rep))
        return;

    // Based on the field type, use a default DataTemplate that we previously loaded via TryFindResourcee

    switch (field.PropType)
    {
    case PropType.Double:  col.CellTemplate = DoubleTemplate; col.DataType = typeof(double); break;

// NOTE: Other types/templates not shown for brevity. default: e.Cancel = true; break; // Some type we don't recognize } col.CellEditTemplate = null; }


But this fails too.  The value supplied to my `DataTemplate' binding is not the individual record field double value, it is the entire Record object.     Likewise every other template reports errors because it is expecting the individual column double/int/string, etc but instead getting the whole `Record` object.

Next I tried using the CellTemplateSelector approach.,  I created one and then set THAT in the event handler above.  But the problem remained the same.  The selector's SelectTemplate method was receiving an object of type Record  

 OK, then I looked at your XAML-SDK where you show a nice example of binding to `ICustomTypeDescriptor`  (the BindingToCustomTypeDescriptor example).  That was a lot of work.  I made my Record class implement that interface just as in your exmaple.  I see its methods being called..  Hooked it up to the GridView. 

But results are exactly the same.  GridView still supplies the Record value instead of the individual cell value to the bindings.

Please tell me what I am doing wrong...



 


Petar Mladenov
Telerik team
 answered on 13 Jul 2022
0 answers
254 views

I'm using the latest version of Telerik UI for WPF - Framework 4.8

and i have the same issue as described here: https://www.telerik.com/forums/the-scroll-bars-are-placed-in-the-tables

from April .. 

Will this issue get fixed sometime soon ? 

or is there a quick fix ?

Martin
Top achievements
Rank 2
Iron
Iron
Iron
 asked on 13 Jul 2022
1 answer
136 views

Want to select cell and freeze this selection by pushing a separate button. Cell should remains in selection state with loosing focus, selecting other cells. Another button will unfreeze all cells in the grid.

Is it possible?

Thanks,

Vladimir Stoyanov
Telerik team
 answered on 13 Jul 2022
1 answer
103 views

I want to select cell, perform some action on the cell value (focus is gone from cell now) and mark this cell as "processed".

I have a button to clear such "permanent" selections.

Is it possible? I saw multiple solutions based on overriding cell selection styles in xaml. Want to make it from view model.

 

Vladimir Stoyanov
Telerik team
 answered on 13 Jul 2022
1 answer
103 views

I would like to indicate/emphasize cells selected for the action.

Example scenario:

1. select 2 cells in the grid;

2. perform some action after pushing separate button "Process selection";

3. now i need to show those previously selected 2 cells despite of clicks on other grid cells or loosing focus on the grid.

There is another button "View All" which will reset grid and clear all "permanently" selected cells.

Looking for suggestions to implement such behavior. Thinking about changing background color, making cell text bold, disabling cells. Any ideas?

CellStyleSelector sample from xaml_sdk demonstrates a static custom cell selection in columns overriding xaml styles. I need to make it dynamic: select cell, perform action, mark cell as processed, select another cell, process it, unmark previous cell, mark new one as processed.

Thank you,

Gennady

Vladimir Stoyanov
Telerik team
 answered on 13 Jul 2022
0 answers
122 views

Good day! Which template is responsible for tooltip while dragging or resizing task? Can we customize this object?

Thank You for answers

Eugeny
Top achievements
Rank 1
 asked on 12 Jul 2022
1 answer
121 views

In code behind, when a user moves the curser in the RadRichTextBox, we check information tagged to span elements. For certain spans, we want the contents to change color, so we set span.ForeColor to a new value, but this doesn't reflect in the UI. I assume there is some update mechanism, but it isn't obvious. I can select the entire span, copy, and paste it in place and it will show the new color, but we want it to happen when a user is moving the cursor.

We're tracking the cursor in the RadDocument.CaretPosition.PositionChanged event handler.

 

Tanya
Telerik team
 answered on 11 Jul 2022
1 answer
361 views

I'm investigating why / how to improve the rendering speed of a rather complex UserControl / Window 

The Window contains a Tab-Control where one of these tabs contain a GridView which is very basic on its own. 

Each of the ~60 rows are bound to an object which has a String + 3x bool properties.

Each time the Window is opene, the list is reset. 

The list of elements is kept in an ObservableCollection (which isn't necessary since the list never change.. but what the heck)

Here's the thing - when Profiling, this Gridview spends 600 msec !! in the Layout phase on the UI Thread... 600 msec !

Is there anything i can do about it ?

(To be honest - the standard WPF ListView spends 2200 msec rendering this list !!!)

 

I'm aware of https://docs.telerik.com/devtools/wpf/controls/radgridview/performance/tips-tricks

- The container has a fixed size

- Each column has a fixed width

- Row Virtualization is enabled

- Scrollbars har hardcoded to be enabled/disabled in advance. 

- Removing the CellTemplates didn't make a difference - time is still ~600msec

- The last thing i havent tried is using the lightweight styling, but i have some bad experiences with those. 

<telerik:RadGridView x:Name="lvCompanyFabrikater"
			            telerik:StyleManager.Theme="Fluent"
			            AutoGenerateColumns="False"
			            Background="{DynamicResource MahApps.Brushes.ThemeBackground}"
			            CanUserFreezeColumns="False"
			            CanUserSearch="False"
			            CanUserSearchInHiddenColumns="False"
			            EnableRowVirtualization="True"
			            GridLinesVisibility="None"
			            GroupRenderMode="Flat"
			            IsFilteringAllowed="True"
			            IsPropertyChangedAggregationEnabled="False"
			            IsReadOnly="True"
			            RowIndicatorVisibility="Collapsed"
			            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
			            ScrollViewer.VerticalScrollBarVisibility="Visible"
			            SelectionMode="Single"
			            ShowGroupPanel="False">
	<telerik:RadGridView.Columns>

		<telerik:GridViewDataColumn Width="100"
					                DataMemberBinding="{Binding FabrikatNavn}"
					                Header="Fabrikat" />

		<telerik:GridViewDataColumn Width="50" Header="Salg">
			<telerik:GridViewDataColumn.CellTemplate>
				<DataTemplate>
					<CheckBox IsChecked="{Binding Salg}" />
				</DataTemplate>
			</telerik:GridViewDataColumn.CellTemplate>
		</telerik:GridViewDataColumn>

		<telerik:GridViewDataColumn Width="60" Header="Service">
			<telerik:GridViewDataColumn.CellTemplate>
				<DataTemplate>
					<CheckBox IsChecked="{Binding Service}" />
				</DataTemplate>
			</telerik:GridViewDataColumn.CellTemplate>
		</telerik:GridViewDataColumn>

		<telerik:GridViewDataColumn Width="85" Header="Reservedele">
			<telerik:GridViewDataColumn.CellTemplate>
				<DataTemplate>
					<CheckBox IsChecked="{Binding Reservedele}" />
				</DataTemplate>
			</telerik:GridViewDataColumn.CellTemplate>
		</telerik:GridViewDataColumn>

	</telerik:RadGridView.Columns>
</telerik:RadGridView>


 

 

Martin
Top achievements
Rank 2
Iron
Iron
Iron
 updated answer on 11 Jul 2022
1 answer
191 views

After opening the RadComboBox in RadGridView (GridViewComboBoxColumn), it is displaying values are in the dropdown.
Scenario-1:
Now, if I don't select any value in the dropdown list (while it is in open) and also click the button. In the 1st click, the dropdown is closed and only in the 2nd click 
button will trigger the function.

I've attached my demo project for your reference. Can you please help me to fix the above issue on the 1st click itself? Is there any possible way to do it, if so please guide me.

Thanks in advance.

Stenly
Telerik team
 answered on 11 Jul 2022
4 answers
225 views
Is it possible to customize the Telerik grid display number column header (row indicator) width in WPF? If so, please let me know how to change the width.
I have used material theme for the Telerik grid, I need to reduce the width of the header column for number displaying column (first column) that extra space I need to adjust narrow.

Also, I've noticed that other than material theme the number column is displayed as expected.

Please let me know how to modify the width of the header column (first column).

Thanks in advance.
Masha
Telerik team
 answered on 11 Jul 2022
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
WatermarkTextBox
DesktopAlert
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
ProgressBar
Sparkline
LayoutControl
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
PasswordBox
Rating
SplashScreen
Accessibility
Callout
CollectionNavigator
Localization
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Edmond
Top achievements
Rank 1
Iron
fabrizio
Top achievements
Rank 2
Iron
Veteran
RobMarz
Top achievements
Rank 2
Iron
Fakhrul
Top achievements
Rank 1
Iron
Tejas
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?