Setting the text of a grouped section

Posted by: hpd71 on 8 September 2017, 4:34 am EST

  • Posted 8 September 2017, 4:34 am EST

    Hi,


     I need to set the text heading of a grouped section.


    I apply my grouping via code, and not via the end user creating a group, so therefore the 'grouped' event does not fire.


    I have 12 groups in my activesheet, and need to be able to set each to be different text.


     Is this possible?


     


     


     


    ' Grouping Code

    <FONT size=2>

    FpSpread1.ActiveSheet.GroupBarVisible = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

    </FONT></FONT><FONT size=2>

    FpSpread1.ActiveSheet.AllowGroup = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> gm </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.Model.GroupDataModel(FpSpread1.Sheets(0).Models.Data)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> si() </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo() {</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo(1, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True</FONT></FONT><FONT size=2>)}


    gm.Group(si)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> si2() </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo() {</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo(3, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True</FONT></FONT><FONT size=2>)}


    gm.Sort(si2)


    FpSpread1.Sheets(0).Models.Data = gm

    </FONT>
  • Replied 8 September 2017, 4:34 am EST

    Hello,


    Since you are grouping the Spread programatically, the events will not fire. You do not need the event since you know when the group has happened. YOu already have the GroupDataModel. ALl you need to do is the last few lines of the code Bob provided to change the text of the first group.

  • Replied 8 September 2017, 4:34 am EST

    Hi Scott,


    Thanks for your reply.


    I have applied the code suggest to my project.


    In my project the code that creates the group, creates around 10 grouped sections(see image attached). The code suggested only changes the text in the first group.


    I have tried to change the suggested code, to work on more than index (0), however it does not seem to have an effect.


    I need to be able to reference each of the grouped heading, and set the text to be different from any other group.


    How can I do this.


     


    Thanks



  • Replied 8 September 2017, 4:34 am EST

    Hello,


    Not every row is a group header. Before calling GetGroup on an index (row number), you should check the IsGroup method to make sure it is a group. Then, you can loop all the rows in the GroupDataModel to determine the rows that are group headers and change the text.

  • Replied 8 September 2017, 4:34 am EST

    Not sure what you mean by 'the text heading'.  You can change the text doing the following...

    Dim gm As FarPoint.Win.Spread.Model.GroupDataModel
    If TypeOf FpSpread1.ActiveSheet.Models.Data Is FarPoint.Win.Spread.Model.GroupDataModel Then

    gm = CType(FpSpread1.ActiveSheet.Models.Data, FarPoint.Win.Spread.Model.GroupDataModel)
    Dim g As FarPoint.Win.Spread.Model.Group = gm.GetGroup(0)
    g.Text = "Your Text Here"

  • Replied 8 September 2017, 4:34 am EST

    Hi,


    I am still not having any luck solving this problem.


    You can see from the attached image the problem I am having. Each group has the words ' category_name : xxxxxxx'. I don't want the 'category_name :' to be displayed, only the xxxxx value.


    Basiclly I just load a dataset with all my data, and then group on one of the cols using the code at the end of this email. This code, does not fire the grouping or grouped event of the grid, so don't seem to be able to do anything at that point.


    I looked at your code, but not sure where I should place the code to have it fire properly.


     

    <FONT size=2>

    FpSpread1.ActiveSheet.GroupBarVisible = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

    </FONT></FONT><FONT size=2>

    FpSpread1.ActiveSheet.AllowGroup = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> gm </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.Model.GroupDataModel(FpSpread1.Sheets(0).Models.Data)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> si() </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo() {</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo(1, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True</FONT></FONT><FONT size=2>)}


    gm.Group(si)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> si2() </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo() {</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.SortInfo(3, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True</FONT></FONT><FONT size=2>)}


    gm.Sort(si2)


    FpSpread1.Sheets(0).Models.Data = gm


     


     

    </FONT>

  • Replied 8 September 2017, 4:34 am EST

    Hi,


    I am sorry to be asking yet again, but I am struggling to apply your points to my code.


    I understand what the issue is, but don't have the skill set to resolve it. (all this rather new to me)


    Would it be possible for you to help me with the attached code and help me out with this.


    This is the last issue I have in my project before its released.


    Thanks very much..


     


    2009/02/grp.zip
  • Replied 8 September 2017, 4:34 am EST

    Hello,


    Try the following code.


            If TypeOf FpSpread1.ActiveSheet.Models.Data Is FarPoint.Win.Spread.Model.GroupDataModel Then


    Dim headCount as Integer = 0
      gm = FpSpread1.ActiveSheet.Models.Data
          For i as Integer = 0 To FpSpread1.ActiveSheet.NonEmptyRowCount - 1
            If gm.IsGroup(i) Then
              headCount+=1
              Dim g As FarPoint.Win.Spread.Model.Group
              g = gm.GetGroup(i)
              Dim s As String
              Select Case headCount
              Case 1:
                 s = Group1Heading
              Case 2:
                 s = Group2Heading
              Case 3:
                 s = Group3Heading
              Case 4:
                 s = Group4Heading
              End Select
              g.Text = s
            End If
          Next


               
            End If

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels