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

How to get the column names in gridview

10 Answers 561 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.
Senthil S
Top achievements
Rank 1
Senthil S asked on 01 Sep 2009, 08:24 AM
Hi,

How to get the Cell or Column details using column names(not using the index) in the Gridview events

Regards

Senthil.S

10 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 01 Sep 2009, 02:40 PM
Hello Senthil S,

Can you please give me some more details on the scenario you are trying to achieve and I will gladly prepare a small sample for you .


Sincerely yours,
Pavel Pavlov
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
Senthil S
Top achievements
Rank 1
answered on 02 Sep 2009, 08:32 AM
Hi Pavel Pavlov ,

Thanks for ur Response..........

My scenario is, i have a gridview, i want to fetch the 5th column or cell  content or value......

so now  i am using like

(e.Row.Cells(4).Content)

Instead of (e.Row.Cells(4).Content) ,what i need is (e.Row.Cells("Status").Content)


My another doubt is which event i have to use to check the each row, when i bind the data in the grid.......

currently i am using rowLoaded event.........but  it first loads all the data and then only this rowLoaded event fires.............

what i need is, the event should be fired when each row is loaded in the gridview....


Thanks & Regards

By

Senthil.S

0
Vlad
Telerik team
answered on 04 Sep 2009, 02:39 PM
Hi Senthil,

Here is an example how to get desired cell by column UniqueName:

            var cell = e.Row.Cells.Where(c => c.Column.UniqueName == "MyColumn").FirstOrDefault();

I'm not sure however about RowLoaded - can you post a bit more info when this event is not raised?

Regards,
Vlad
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
Jax
Top achievements
Rank 2
answered on 22 Dec 2009, 10:34 AM
Vlad,

What if VirtualColumns are turned on, and the columns / cell that I'm looking for is not in view?
It looks like Row.Cells only contains the cells that can be viewed (not virtualized)
0
Vlad
Telerik team
answered on 23 Dec 2009, 02:17 PM
Hello Jax,

Well you cannot since there are no cells created for columns out of view. If we create these cells we will kill the grid performance.

Greetings,
Vlad
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
Jax
Top achievements
Rank 2
answered on 04 Jan 2010, 05:28 AM
Vlad,

Is it then possible to programmatically scroll the grid so that the cell gets created?

I'm trying to row-level validation (a common scenario imo), and focus a cell that has the validation error.
0
Nedyalko Nikolov
Telerik team
answered on 05 Jan 2010, 02:49 PM
Hi Jax,

We will introduce some improvements related to this issue with the upcoming service pack. Meanwhile you can take a look at the attached example which demonstrates how to meet your goals. Pay more attention to the PersonValidator class which sets the invalid property name. Steps to get this working:

  1. Put "BirthDay" cell into edit mode.
  2. Leave the edited row (in order to trigger RowValidation).

You will notice that now "Age" cell is in edit mode.
Let me know if it does not help.

Sincerely yours,
Nedyalko Nikolov
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
Jax
Top achievements
Rank 2
answered on 07 Jan 2010, 07:53 AM
Thanks for the reply Nedyalko, but my issue isn't to get validation up and running (we have it working fine).
The problem comes in (using your example) when column virtualization is turned on, and the age column is not visible.

In your code, line 32 in MainPage will throw an exception, because the Age column does not exist because it is not visible.
In the meantime, instead of calling
errorCell = e.Row.GetCellFromPropertyName(valResult.PropertyName); //throws exception
I do something like
errorCell = (GridViewCell) e.Row.Cells.Where(c => c.Column.UniqueName == propertyName).FirstOrDefault(); //no exception
if (errorCell != null) // is null if not visible
{ logic here }

What I'm after is to force the grid to navigate to the cell which is not yet visible.
0
Nedyalko Nikolov
Telerik team
answered on 07 Jan 2010, 02:54 PM
Hi Jax,

Indeed you are right due to horizontal virtualization invisible cells are not created, so you cannot find them. You can scroll RadGridView horizontally with a single line of code which solves the problem. Insert the following code before the line that throws the exception (#32).

this.radGridView.ScrollIntoView(null, this.radGridView.Columns[valResult.PropertyName]);

To clarify what ScrollIntoView() method do with first parameter "null", just brings the column (second parameter) into view. This action creates necessary cell and everything should work fine. Let me know how this works on your end.

Sincerely yours,
Nedyalko Nikolov
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
Jax
Top achievements
Rank 2
answered on 08 Jan 2010, 06:10 AM
of course!
Thanks - works like a charm :)
Tags
GridView
Asked by
Senthil S
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Senthil S
Top achievements
Rank 1
Vlad
Telerik team
Jax
Top achievements
Rank 2
Nedyalko Nikolov
Telerik team
Share this question
or