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

1 Answer 18 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
0
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.

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