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

Tag

9 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tommy Anderson
Top achievements
Rank 1
Tommy Anderson asked on 23 Jun 2009, 03:51 PM
For each row I add in the GirdView, I set a tag like this

GridViewDataRowInfo row = aGridView.Rows.AddNew();
row.Tag = 1;

RadGridView.Rows.Add(row);

and when I click on a row in the Girdview, I want to get the associated tag to the selectedrow.

The problem is that RadGridView.SelectedRows[0].tag is always null.

I found out that RadGridView.SelectedRows[0] return a GridViewRowInfo and not a GridViewDataRowInfo.

Is there a quick way to have the tag of the GridViewDataRowInfo object of the selectedrow ?

 



9 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 24 Jun 2009, 11:55 AM
Hi Tommy Anderson,

Thank you for contacting us. We found a bug in our code which we fixed so your code should work in Q2 2009 SP1 which is to be released in a couple of weeks. Your code is a bit wrong though:

instead of

GridViewDataRowInfo row = aGridView.Rows.AddNew(); 
row.Tag = 1; 
RadGridView.Rows.Add(row); 

use just

GridViewDataRowInfo row = aGridView.Rows.AddNew(); 
row.Tag = 1; 

AddNew method adds the new row to the collection as well.

Do not hesitate to write us back if you have further questions. I have updated your Telerik points for helping us find a bug.

Regards,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Tommy Anderson
Top achievements
Rank 1
answered on 26 Jun 2009, 03:53 PM
You are right about the rows.add. I noticed after that it was adding the row twice.

Thank you.
0
Phillip
Top achievements
Rank 1
answered on 07 Sep 2009, 02:26 PM
Hi,

I am experiencing the same problem, and have Q2 2009 SP1. I cannot see a reference to this problem in the release notes and don't think the fix got into this release. Can you confirm that it has/has not ?

Phillip.
0
Nick
Telerik team
answered on 10 Sep 2009, 11:56 AM
Hi Phillip,

Thank you for contacting us. I checked that and it seems fixed. We have probably missed to include it in the release notes. Can you send us the code that you use when reproducing the issue. Thank you very much for your time. Here is a link to the online documentation about the Tag property.

Sincerely yours,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Phillip
Top achievements
Rank 1
answered on 10 Sep 2009, 03:13 PM
Nik,

Thanks for your reply. I built a single form project with a RadGridView with a single Command button column. I put the followng code in the form.

        protected override void OnLoad(EventArgs e)  
        {  
            base.OnLoad(e);  
            this.radGridView1.Rows.AddNew();  
        }  
 
        private void radGridView1_RowsChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)  
        {  
            if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add)  
            {  
                Telerik.WinControls.UI.GridViewDataRowInfo newRowInfo = e.NewItems[0] as Telerik.WinControls.UI.GridViewDataRowInfo;  
                System.Diagnostics.Debug.Assert(newRowInfo.Tag != null);  
            }  
        }  
 
        private void radGridView1_CommandCellClick(object sender, EventArgs e)  
        {  
            Telerik.WinControls.UI.GridCommandCellElement commandButtonCell = sender as Telerik.WinControls.UI.GridCommandCellElement;  
            System.Diagnostics.Debug.Assert(commandButtonCell.RowInfo.Tag != null);  
 
        }  
 
        private void radGridView1_RowsChanging(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)  
        {  
            if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add)  
            {  
                Telerik.WinControls.UI.GridViewDataRowInfo newRowInfo = e.NewItems[0] as Telerik.WinControls.UI.GridViewDataRowInfo;  
                newRowInfo.Tag = "Sample Tag Value";  
            }  
        } 

I used Q2 2009 SP1. When the RowsChanging event is fired, it puts in the Tag property. When the RowsChanged is fired, the Tag property is still there. When I click on the command cell and the CommandCellClick is fired, the Tag has gone to Null.

Hope this helps.
0
Nick
Telerik team
answered on 11 Sep 2009, 09:05 AM
Hi Phillip,

Thank you for contacting us. I guess it is pretty unintuitive, but the code snippet below should do the job:

((GridViewNewRowInfo)commandButtonCell.RowInfo ).DataRowInfo.Tag 

Do not hesitate to write me back if you have further questions.

Greetings,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Phillip
Top achievements
Rank 1
answered on 11 Sep 2009, 11:00 AM
Sorry, this doesn't work for me; In my example I replaced the Debug.Assert line with 
 
if (commandButtonCell.RowInfo.GetType() == typeof(Telerik.WinControls.UI.GridViewNewRowInfo))  
            {  
                System.Diagnostics.Debug.Assert(((Telerik.WinControls.UI.GridViewNewRowInfo)commandButtonCell.RowInfo).DataRowInfo.Tag != null);  
            }  
            else 
            {  
                System.Diagnostics.Debug.Assert(commandButtonCell.RowInfo.Tag != null);  
            } 

To cater for the situation where the row might be either a "new row" or a "non new row".

However in all my tests, if the RowInfo type is GridViewNewRowInfo the .DataRowInfo property is null. I therefore cannot use your solution to get at the tag property because I the DataRowInfo property is not set on a new row.

Looking forward to getting a different solution

Phillip
0
Phillip
Top achievements
Rank 1
answered on 14 Sep 2009, 12:49 PM
Nick,

My forum summary page tells me you've replied as the last contributor to this thread, but I cannot seem to be able to see your answer - did you respond ?
0
Nick
Telerik team
answered on 14 Sep 2009, 01:14 PM
Hi Phillip,

We will be happy to help you further after you provide the requested details in your other support ticket (id: 241240).

Regards,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Tommy Anderson
Top achievements
Rank 1
Answers by
Nick
Telerik team
Tommy Anderson
Top achievements
Rank 1
Phillip
Top achievements
Rank 1
Share this question
or