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

grouped column should be displayed in one record

9 Answers 399 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
anu
Top achievements
Rank 1
anu asked on 03 Jun 2008, 09:09 PM
Hi Telerik,

I have created a report and there are some different column in it.
I have used grouping to one column and it works fine.
My problem is the grouping column should be displayed only once and not in the other records. Something like this:

At present:

column1  column2  column3
-----------------------------
fruit         apple         red
fruit        banana       green
fruit        mango       yellow
car         toyota       black
car         nissan        silver

What I want is:

column1  column2  column3
-----------------------------
fruit         apple         red
              banana       green
              mango       yellow
car         toyota       black
              nissan        silver

Note: I dont want separate header for the groups. I want the group columns to be included in the normal fields only. Any suggestion?

9 Answers, 1 is accepted

Sort by
0
rick0735
Top achievements
Rank 1
answered on 03 Jun 2008, 10:21 PM
Write a user function that returns a string. Pass in the column1 (grouping) value. Compare it to the last one you printed. If it's the same, return an empty string. If it's different, store the new value and return it as the function result. You'll need to declare a (module-level) string variable to hold the value of the last-printed grouping value in between item bindings.

I'm interested to see if Telerik has a different response, but this should work.
0
rick0735
Top achievements
Rank 1
answered on 03 Jun 2008, 10:26 PM
P.S.: There are also some possibilities in the ItemDataBound event - some hints appear in the post right before yours, especially the link to setting textbox visibility. See http://www.telerik.com/community/forums/thread/b311D-bebkeg.aspx
0
anu
Top achievements
Rank 1
answered on 04 Jun 2008, 09:16 PM
thank you for your reply, tried some coding in the ItemDataBound and also ItemDataBounding events but all in vain. any other suggestion?
0
rick0735
Top achievements
Rank 1
answered on 04 Jun 2008, 10:38 PM
This works (based on Northwind ProductCategory view):

        private void detail_ItemDataBound(object sender, System.EventArgs e)  
        {  
            // Get the detail section object from sender  
            
            Processing.DetailSection section = (sender as Processing.DetailSection);  
            // From the section object get the DataRowView  
            DataRowView dataRowView = (DataRowView)(sender as Processing.DetailSection).DataItem;  
            if (dataRowView["CategoryName"].ToString() != lastCategory)  
                lastCategory = dataRowView["CategoryName"].ToString();  
            else  
            {  
                Processing.ReportItemBase[] categoryNames = (Processing.ReportItemBase[])section.Items.Find("textBox1", false);  
                if (categoryNames.Length > 0)  
                {  
                    Processing.TextBox categoryName = categoryNames[0] as Processing.TextBox;  
                    categoryName.Text = string.Empty;  
                }  
            }  
        }  
 
0
anu
Top achievements
Rank 1
answered on 05 Jun 2008, 09:40 PM

thank you very much for your reply.
I implemented your code like this:

Private

Sub DetailSection1_ItemDataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DetailSection1.ItemDataBound

Dim section As Processing.DetailSection = (TryCast(sender, Processing.DetailSection))Dim dataRowView As DataRowView = DirectCast((TryCast(sender, Processing.DetailSection)).DataItem, DataRowView)
Dim lastItem As String = "" 
Dim items As Processing.ReportItemBase() = DirectCast(section.Items.Find("TextBox10", False), Processing.ReportItemBase())
If items.Length > 0 Then
Dim item As Processing.TextBox = TryCast(items(0), Processing.TextBox)
'For Each item In items
If dataRowView("CODES_TITLE").ToString() <> lastItem Then
lastItem = dataRowView("CODES_TITLE").ToString()
Else
item.Text = String.Empty
End If
'Next item
End If

End Sub

Here when I intialise the lastItem with a emty string value, it goes to the if condition and the condition becomes true and its returning all the rows as usual whereas if I intialise the lastItem with the dataRowView("CODES_TITLE").ToString() value then the if condition becomes false and its returning empty values for all the rows.
Then I applied loop(not sure whether I have applied it correctly or not) , you can see the commented ones.

What is to be added to the code at this point?

0
Accepted
rick0735
Top achievements
Rank 1
answered on 06 Jun 2008, 12:15 AM
Rats! I thought about this but forgot to include it in my last reply.

The problem is with the declaration 
Dim lastItem As String = "" 
which you contain inside your routine - you don't see the declaration in my code because it's right after the class declaration. "lastItem" needs to be declared outside your subroutine (ie, at the module level), because as you have it right now, you're re-declaring the variable each time you enter the ItemDataBound event handler (entered once per data row), and I would expect exactly the behavior you are describing. If you declare it outside the handler, it will preserve its value.



0
Ivan
Telerik team
answered on 06 Jun 2008, 11:26 AM
Hi Anu,

In fact Rick has already explained all you need. I will just attach a sample solution with two reports that demonstrates the case:
  • The first report (Report1) relies on DataBound event handler to modify the Text property of the TextBox.
  • The second report (Report2) uses a UserFunction to filter the value.
Please note the UserFunction should be public static (Public Shared in VB) and the old-value-storage should be static too.

Please try the sample and let me know if you have any other questions.

All the best,
Ivan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
anu
Top achievements
Rank 1
answered on 06 Jun 2008, 02:06 PM
Works like a charm....Thank you so much Rick.
@Ivan thank you for the sample. I wish this could be made as a property(hide duplicates) like in othe reporting services. No issue though.
0
Rossen Hristov
Telerik team
answered on 06 Jun 2008, 02:55 PM
Hi anu,

We are glad that you have resolved that issue. We will definitely consider your suggestion for a future version of Telerik Reporting.

Sincerely yours,
Ross
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
anu
Top achievements
Rank 1
Answers by
rick0735
Top achievements
Rank 1
anu
Top achievements
Rank 1
Ivan
Telerik team
Rossen Hristov
Telerik team
Share this question
or