WPF RadGridView: Can I customize the Row Indicator to function more like Excel's row indicator?

1 Answer 67 Views
GridView
Patrick
Top achievements
Rank 1
Patrick asked on 07 Mar 2022, 04:00 PM

Hello,

I would like to know if there is a way to customize (or alter) the RadGridView-Row Indicator to function more like the row indicator in Excel that supports Selection of rows and Automatic Row Numeration?

Or perhaps any way to set a Custom Row Indicator in a Custom RadGridView?

 

thank you,

Patrick

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Dilyan Traykov
Telerik team
answered on 09 Mar 2022, 11:13 AM

Hello Patrick,

Rather than customize the default indicator, what I can suggest is to try an approach similar to the one demonstrated in the Row Number demo from our WPF Controls Samples application.

In other words - to use a custom column, in which you can display a custom element (such as TextBlock) and calculate the index of the items as well as add custom logic (such as selection of the row upon click).

    public class MyColumn : Telerik.Windows.Controls.GridViewColumn
    {
        public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            TextBlock textBlock = cell.Content as TextBlock;

            if (textBlock == null)
            {
                textBlock = new TextBlock();
            }

            textBlock.Text = string.Format("{0}", this.DataControl.Items.IndexOf(dataItem) + 1);

            return textBlock;
        }

        protected override void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)
        {
            base.OnPropertyChanged(args);

            if (args.PropertyName == "DataControl")
            {
                if (this.DataControl != null && this.DataControl.Items != null)
                {
                    this.DataControl.Items.CollectionChanged += (s, e) =>
                    {
                        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
                        {
                            this.Refresh();
                        }
                    };
                }
            }
        }
    }

In addition, you'd need to hide the default indicator by setting the RowIndicatorVisibility property to Collapsed.

Please give this a try and let me know if such an approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Patrick
Top achievements
Rank 1
commented on 06 Feb 2023, 09:03 PM

Hello Dilyan,

I'm pleased to say your solution worked as intended and did indeed answer my previous question.

However, I would like to know if there's any modifications I can make that would allow column filtering discrimination?

Currently when I filter a certain column, the row number stays the same even when the underlying data item is different.

I was hoping that the Row Number is correlated with the data items being filtering (with out adding a property to the underlying ItemsSource data items).

 

Thank you,

Patrick.

Dilyan Traykov
Telerik team
commented on 09 Feb 2023, 10:10 AM

Hello Patrick,

I'm happy to hear that the proposed solution worked for you.

I could not, however, infer what you mean by "column filtering discrimination", can you please elaborate on this?

I tested the behavior you described with the Row Number demo I referenced earlier, however, the numbers are updated as expected at my end upon filtering:

Can you please specify whether this differs from the behavior you observe at your end? If that is the case, please send over a small sample project which demonstrates your setup and the issue you observe and I will gladly assist you further.

Tags
GridView
Asked by
Patrick
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or