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

More than 2 data relations, determining table on click

7 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daryl
Top achievements
Rank 1
Daryl asked on 10 May 2011, 09:02 PM
I have auto generated columns on (I want that so the code can be generic, I don't want to specify table names and layout).
I am binding to 3 tables in a DataSet by an Id (PROPERTY_ID) , so there are three levels of nesting.

 

 

 

 

 

 

 

 

 

 

 

// start code snippet...
x_GRID.AutoGenerateColumns = true
  
dd.Tables.Add(t); // PARENT TABLE 
dd.Tables.Add(t0); // CHILD TABLE A
  
dd.Tables.Add(t1); // CHILD (CHILD) TABLE B - This is a child of table A
  
dd.Relations.Add(new DataRelation("Prop_Params", dd.Tables[0].Columns["PROPERTY_ID"], dd.Tables[1].Columns["PROPERTY_ID"])); 
  
   
dd.Relations.Add(new DataRelation("Section_Params", dd.Tables[1].Columns["PROPERTY_ID"], dd.Tables[2].Columns["PROPERTY_ID"]));
  
x_GRID.ItemSource = dd;
  
// end code snippet...
  
A few questions - I am in the DataLoading event (see questions in comments below)
void wpfgv_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e) 
{
   var dataControl = (GridViewDataControl)sender; 
  
// 1. ParentRow != null tells me that it is a child table,
// but I need to know which CHILD TableName it is
// So that I can do different things for child table A and child (child) table B
// (like hide a column that child table A has but child table B does not.  
// How do I get the TableName of what dataControl is referring to
// (I could not seem to find it in my debugging watches)???
   if (dataControl.ParentRow != null
   {
      dataControl.ShowGroupPanel = false ;
  
// 2. I "think" because I have AutoGenerateCols = true, datacontrol.Columns = null
// so this crashes if left uncommented...
// just trying to verify my thinking on why it is null. 
  
dataControl.Columns["PROPERTY_ID"].IsVisible = false// will crash
  
// 3. x_GRID is the name of my GridView Control.  
// While this works, it only hides the PROPERTY_ID of the
// PARENT table column called PROPERTY_ID 
// and does NOT hide child columns of the same name (which is exactly
// the opposite of what I want to do).
// Is there a way without setting x_GRID.AutoGenerateColumns = false
// and binding each column
// in code or xaml to hide just columns of the children???
  
    x_GRID.Columns["PROPERTY_ID"].IsVisible = false ;  
   }
}

 

Thanks,

Daryl

 

 

 

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 May 2011, 06:32 AM
Hi Daryl,

 Can you clarify what is the exact question? 

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Daryl
Top achievements
Rank 1
answered on 11 May 2011, 02:21 PM
See the enumerated questions in the code comments 1,2 and 3.  This isn't clear enough?

0
Pavel Pavlov
Telerik team
answered on 12 May 2011, 12:14 PM
Hi Daryl,

Please find my answers in bold.

1. ParentRow != null tells me that it is a child table,
// but I need to know which CHILD TableName it is
So that I can do different things for child table A and child (child) table B 
(like hide a column that child table A has but child table B does not. 
How do I get the TableName of what dataControl is referring to 
(I could not seem to find it in my debugging watches)???

If you have a refference to the GridView, then you can check its itemssource something like :
((DataTable)childGridView.ItemsSource).Name



2. I "think" because I have AutoGenerateCols = true, datacontrol.Columns = null
// so this crashes if left uncommented...
// just trying to verify my thinking on why it is null.

I am not sure what is the question here

// 3. x_GRID is the name of my GridView Control.
// While this works, it only hides the PROPERTY_ID of the
// PARENT table column called PROPERTY_ID
// and does NOT hide child columns of the same name (which is exactly
// the opposite of what I want to do).
// Is there a way without setting x_GRID.AutoGenerateColumns = false
// and binding each column
// in code or xaml to hide just columns of the children???


If I get the question right - you need to hide specific columns, while autogenerating the columns and not defining them explicitly. 
A  way to do that is to handle the AutoGenerating event . Inside the event handler you can hide a column
by setting e.cancel - true inside the event handler.
An  alternative is also to handle the dataloaded event of the gridvuew and set the visibility to "collapsed" for columns you need to hide.

Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Daryl
Top achievements
Rank 1
answered on 12 May 2011, 02:55 PM
Thanks for the reply.

Question #1 (still not working) : Please see the comments below on getting the TableName in the DataLoading Event...this is still something I'd like to do.

void wpfgv_DataLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs e)
{
      // This won't work here because ItemsSource is a DataSet
        // (not DataTable) with relations. That is
        // why I
am struggling in this Event to figure out WHICH of the
      // TABLES in my DataSet are being loaded when this Event fires.
      string ss = ((DataTable)e.ItemsSource).TableName;  
 
     // ((GridViewDataControl)sender).Columns is null here 
}

Question #2
, I would have expected ((GridViewDataControl)sender).Columns to be the collection of columns in my auto-generated table in the DataLoading event, but it is in fact NULL at this point in the code.

Question #3, I figured out to use the AutoGenerate event to hide the columns before you replied.  While this works for me, it would still be nice in this event (much like DataLoading event), to know the ROOT TableName that I am dealing with within the DataSet when the event fires.

Thanks for your time.
0
Pavel Pavlov
Telerik team
answered on 18 May 2011, 10:35 AM
Hi Daryl,

Having only fragments of the code makes it extremely difficult to sort the things out. May be I could be in more help if I had more info on how your hierarchy is set.( e.g. see some code, test to see what happens with a small sample data) .

Can we iterate over a small runnable project? Actually if you send me one and let me know what the expected behavior is , I can do the implementations for you.

I believe this is the fastest way to solve the issue.

Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Daryl
Top achievements
Rank 1
answered on 18 May 2011, 07:19 PM
I'm not sure how to make it any more apparent.

If you bind to a DataSet with 3 or more "datarelated" tables in it, how do you figure out the TABLE NAME of that is being acted upon in the DataLoading event?

You CAN tell if it is a parent or child, but you can't tell WHICH child it is (at least not as far as I can tell).

Thanks,

Daryl
0
Tsvyatko
Telerik team
answered on 24 May 2011, 12:48 PM
Hello Daryl,

 As I understand your question, you are looking for mechanism to get what is level of the grid to which the data load is fired as well as the root grid (respectively its itemssource).

You can achieve this by using the following code:

void Grid_DataLoading(object sender, GridViewDataLoadingEventArgs e)
{
 
    var originalGrid = (RadGridView)sender);
 
    int level = 0;
    GridViewDataControl rootDataControl = originalGrid;
 
    while(rootDataControl.ParentRow!=null && rootDataControl.ParentRow.GridViewDataControl!=null)
    {
        level++;
        rootDataControl = originalGrid.ParentRow.GridViewDataControl;
    }
     
}

Let us know if this helps.

Regards,
Tsvyatko
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Daryl
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Daryl
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Tsvyatko
Telerik team
Share this question
or