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

Dynamic Gridview

13 Answers 182 Views
GridView
This is a migrated thread and some comments may be shown as answers.
indian
Top achievements
Rank 1
indian asked on 22 Dec 2009, 03:59 PM
Hi,

i want to create a dynamic Gridview, means:

Create Column at runtime; Create Rows at runtime and create Cells at runtime.

My try
GridViewDataColumn Col1 = new GridViewDataColumn();  
Col1.Header = "Col1";  
radGridView1.Columns.Add(Col1);  
 
GridViewRow pRow = new GridViewRow();  
GridViewCell pCell = new GridViewCell();  
pCell.Content = "Test";  
pRow.Cells.Add(pCell);  
radGridView1.Items.Add(pRow); 

is it possible to create it this way? My grid doesn't shows any results.
After request the GridItems (radGridView1.Items[0]), i get back a GridViewRow.

What are my mistakes?

Best,
Christoph
 

13 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 23 Dec 2009, 06:41 AM
Hello Christoph,

Creating rows and cells is not possible however you can prepare simple IEnumerable<YourType> with desired items and properties and assign this to the grid ItemsSource. You can check also my DataTable for more info about dynamic types in Silverlight.

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
indian
Top achievements
Rank 1
answered on 23 Dec 2009, 09:23 AM
Thanks,
great class!

One more question. When I create my own object Column (CellTag) with more than one properties, the cell displayed the classname.
Is it possible to declare a defaultproperty to display this?

public class CellTag  
  public string Display; 
  public string Hide; 
 
 
 
table.Columns.Add(new DataColumn() { ColumnName = "CustomType", DataType = typeof(CellTag) }); 

Best,
Christoph



0
Vlad
Telerik team
answered on 23 Dec 2009, 09:40 AM
Hello Christoph,

You can override ToString() for your class and return desired value.

Sincerely yours,
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
indian
Top achievements
Rank 1
answered on 23 Dec 2009, 10:01 AM
Hi,

now the Cell displayed the right value! :-)

But when I try to edit the Cell the validation of the Grid says that I entered the wrong Valuetype...

Christoph
 
0
Vlad
Telerik team
answered on 29 Dec 2009, 07:26 AM
Hi Christoph,

I've attached an example project to illustrate you how to achieve your goal.

All the best,
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
Sravan Kumar Uddarraju
Top achievements
Rank 1
answered on 13 Jan 2010, 04:35 PM

Thanks Vlad.  Attached example (silverlightdatatable.zip ) really served my purpose. Next , I was trying to add MouseEnter and MouseLeave events for each row by using MouseLoaded (Gr_RowLoaded) event. When I mouse over on the row, event fires, but I am not really sure how to get values from that row.  The row has got my custom objects (Row_MouseEnter) in it. Following approach  (Row_MouseEnter) is correct to get the row values?

 

       

void Row_MouseEnter(object sender, MouseEventArgs e)  
 
        {  
 
   
 
            if (!(sender is Telerik.Windows.Controls.GridView.GridViewRow))  
 
                return;  
 
   
 
            Telerik.Windows.Controls.GridView.GridViewRow row =     (Telerik.Windows.Controls.GridView.GridViewRow)(sender);  
 
   
 
            Mynamespace.Graphic gr = row.Cells[row.Cells.Count-1].Content as Graphic;  
 
   
 
            if (gr == null)  
 
                return;  
 
   
 
            HighlightGraphics(gr , 1);  
 
            gr.Select();  
 
   
 
        }  
 
   
 
        private void Gr_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)  
 
        {  
 
            e.Row.MouseEnter += Row_MouseEnter;  
 
            e.Row.MouseLeave += Row_MouseLeave;  
 
            e.Row.MouseLeftButtonUp += new MouseButtonEventHandler(Row_MouseLeftButtonUp);  
 
        }  
 

0
Pavel Pavlov
Telerik team
answered on 14 Jan 2010, 09:42 AM
Hi Sravan Kumar Uddarraju,

Your code seems OK but there is actually a simpler solution. There is no need to seek the data in cells.
You can get access to your business object through the DataContext property of the row.

Something like :

MyBusinessObject = ((UIElement)sender).DataContext as MyBusinessObject;

within the Row_MouseEnter event handler.

Regards,
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
Sravan Kumar Uddarraju
Top achievements
Rank 1
answered on 19 Jan 2010, 09:22 PM

Thanks Pavlov.  

I have another question. I have object and I would like to find that object in the grid view and then select that row and make it visible in the view by using ScrollIntoView method.  My code is working fine. But sometime application crashes.  If I comment out the ScrollintoView code, application is not crashing. 

 

1)      Is attached process working fine but, is there anyway directly get the row based on the provided value?

2)      If I use ScrollintoView method, why my application is crashing.

 

        private void GraphicsLayer_MouseEnter(object sender, Graphic graphic, MouseEventArgs args)  
        {  
            _gridView.Focus();  
 
            IList<GridViewRow> Rowitems = _gridView.ChildrenOfType<GridViewRow>();  
 
            foreach (var item in _gridView.Items)  
            {  
                if (item.ToString().Contains(graphic.Attributes["ROUTE_CODE"].ToString()) == true)  
                {  
                    _gridView.SelectedItems.Clear();  
                    _gridView.SelectedItem = item;  
                    //_gridView.ScrollIntoView(_gridView.SelectedItem);  
                    _gridView.SelectionMode = System.Windows.Controls.SelectionMode.Single;  
                    HighlightGraphics(graphic, 1);  
                    return;  
                }  
            }  
            _map.Focus();  
 
        }  
 
        private void GraphicsLayer_MouseLeave(object sender, Graphic graphic, MouseEventArgs args)  
        {  
 
                HighlightGraphics(graphic, 0.1);  
                _gridView.Focus();  
                _gridView.SelectedItem = null;  
        } 

Regards,
Srv

0
Pavel Pavlov
Telerik team
answered on 20 Jan 2010, 09:52 AM
Hi Sravan Kumar Uddarraju,

Can you please give me some more details on the crash - e.g. the exception , maybe some stack trace ? Also any information/ source code  that may help me to reproduce the problem here will be appreciated.
An alternative is to send me a small project reproducing the issue. To be able to attach a project  you will need to open a support ticket.

Best wishes,
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
Sravan Kumar Uddarraju
Top achievements
Rank 1
answered on 20 Jan 2010, 02:54 PM
Pavlov,

Here is the functionality. I have graphic features I will be displaying those graphic attributes in the gridview. When mouse enter into the record in the grid, corresponding graphic feature will be highlighted. Same way, I would like to implement the functionality when mouse over on to the graphic, it should highlight (_gridView.SelectedItem) corresponding record in the gridview.

 

I did implement this functionality and its working fine. But if mouse moves over fast on to the graphics, then application crashes. I think because of the speed of mouse over, ScrollIntoView is giving problem. Here I am attaching the exception screenshot.

GraphicsLayer_MouseEnter (in my previous post) event fires when mouse over on graphic
GraphicsLayer_MouseLeave unhighlight the graphic, when leave the mouse from the graphic
 

Regards,
Srv

0
Pavel Pavlov
Telerik team
answered on 25 Jan 2010, 10:25 AM
Hello Sravan Kumar Uddarraju,

Despite all my efforts , I was unable to reproduce the problem here.

I can give only some advice :
Please check  how many times is ScrollIntoView called ?  should be only one . Such problems may occur if layout update occurs too frequently ( the Silverlight framework has some internal limits) .

For example we had such problem , when RadGridView was placed besides some kind of 3d party map control , which had a bug causing updates to the layout of the whole window.

This is just a guess.

Best wishes,
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
Sravan Kumar Uddarraju
Top achievements
Rank 1
answered on 09 Mar 2010, 05:16 PM

I have another question.  My Dynamic gridview  has the text column with the URL. I need to create another hyperlink column programmatically (in code behind) and update the URL from my existing text column of the dynamic grid.

 Please send me the sample code to create the new Hyperlink column and update the cell values with one of the text columns for my dynamic grid.

0
Sree Rachakonda
Top achievements
Rank 1
answered on 15 Mar 2010, 11:42 AM
The help is great..... I got solution for some of my issues..... Telerik help keep going guys.....
Tags
GridView
Asked by
indian
Top achievements
Rank 1
Answers by
Vlad
Telerik team
indian
Top achievements
Rank 1
Sravan Kumar Uddarraju
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Sree Rachakonda
Top achievements
Rank 1
Share this question
or