This is a migrated thread and some comments may be shown as answers.

[Solved] RowLoaded event

7 Answers 263 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jon Bergquist
Top achievements
Rank 1
Jon Bergquist asked on 24 Mar 2009, 02:54 PM
How do you determine the index of the row being loaded in the RowLoaded event?  I want to apply styling to the first row but there does not seem to be such a property in the RowLoadedEventArgs object.

Thanks

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Mar 2009, 04:49 PM
Hi Jon,

You can use a bit different approach to achieve the same:
            bool shouldApply = true
        private void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e) 
        { 
            if (e.Row.Record is DataRecord && ((DataRecord)e.Row.Record).Data != null && 
                shouldApply) 
            { 
                // your code goes here 
                shouldApply = false
            } 
        } 


Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Jon Bergquist
Top achievements
Rank 1
answered on 24 Mar 2009, 05:47 PM
Thanks for that but I still need to determine the rows index because I only want to format the 1st row.   In general, how does one access the rows collection in code?

Thanks

Jon
0
Vlad
Telerik team
answered on 25 Mar 2009, 06:23 AM
Hi Jon,

You can use our extension methods - RadGridView1.ChildrenOfType<GridViewRow>().

All the best,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Jon Bergquist
Top achievements
Rank 1
answered on 25 Mar 2009, 06:00 PM
Ok so here is what I've done.  Obviously, I can't call this until after all the rows are loaded so I tried setting an event for DataLoaded but apparently that gets called for every row.  So the first question is how do I know when all rows are loaded?

The other thing I had to do (simulating all records being loaded via a button click) is to write the following to pull the first row because  doing AppointmentGrid.ChildrenOfType<GridViewRow>().First() seems to return a header row.

    var rows = AppointmentGrid.ChildrenOfType<GridViewRow>().ToList();
           
            if(rows.Count > 1)
            {
                var row = rows[1];
                row.IsEnabled = false;
                row.Background = new SolidColorBrush(Colors.Orange);
            }

I'm spending way to much time to disable and format the first row when it should just be mygrid.rows[0].IsEnabled = false or I should be able to reference the row via an index.  Am I missing something here?

Thanks
0
Vlad
Telerik team
answered on 30 Mar 2009, 09:56 AM
Hello Jon,

Due to rows virtualization even the default MS DataGrid control does not have such property (Rows[]).
We will do our best to provide better way for accessing rows and cells as soon as possible.

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Jon Bergquist
Top achievements
Rank 1
answered on 31 Mar 2009, 11:27 PM
Sounds like for now I will have to use the extension methods.  Is the following code the best way to grab the 1st row?

var rows = AppointmentGrid.ChildrenOfType<GridViewRow>().ToList();
           
            if(rows.Count > 1)
            {
                var row = rows[1];
                row.IsEnabled = false;
                row.Background = new SolidColorBrush(Colors.Orange);
            }

What would be the event to listen for when the grid completes the binding process so that I can call the aforementioned code?

Thanks

Jon



0
Vlad
Telerik team
answered on 03 Apr 2009, 03:00 PM
Hello Jon,

Generally this event is DataLoaded however the grid visual elements are not yet created at this stage - you will need to force this:
    public partial class Page : UserControl 
    { 
        public Page() 
        { 
            InitializeComponent(); 
 
            var data = from i in Enumerable.Range(0, 10) 
                       select new MyObject() 
                       { 
                           ID = i, 
                           Name = String.Format("Name {0}",i) 
                       }; 
 
            RadGridView1.ItemsSource = data; 
            RadGridView1.DataLoaded += new EventHandler<EventArgs>(RadGridView1_DataLoaded); 
        } 
 
        void RadGridView1_DataLoaded(object sender, EventArgs e) 
        { 
            RadGridView1.Measure(new Size()); 
 
            var firstDataRow = RadGridView1.ChildrenOfType<GridViewRow>().FirstOrDefault(); 
 
            if (firstDataRow != null
            { 
                // 
            } 
        } 
    } 
 
    public class MyObject 
    { 
        public int ID { getset; } 
        public string Name { getset; } 
    } 


All the best,
Vlad
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Jon Bergquist
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jon Bergquist
Top achievements
Rank 1
Share this question
or