Example of report with "header" showing letter of the alphabet (like an index)

Example of use, you want to print off a list of all of your clients, but want to have a header show each letter of the alphabet such as the header would be a letter A and then all clients that start with the letter A would be listed under, and then the next header would be a letter B and all clients that start with the letter B would be listed under and so on.

image lost

Bit of a funky script to do this, as you need to store the variable of current character in the header and compare it to each client to see when next list the next, and than print or not print the header depending, as well as move and resize the labels that do or do not show.

Have attached an example report template where this has been done.

Please note as with all report template example and tutorials, you are welcome to download and use as is. If any additional support required (i.e. you are customizing and need help editing the script, or using that script to create your own custom report template, etc), please send details as per the Custom-report-templates topic and would be hapy to provdie a quote

ReportHeader band Before Print script just has the variable declared that we will use to “hold” what is the charcter to use for the header " "

string CurrentGroupCharacter="";

GroupHeader1 has its Group Fields property set to sort ascending by the Client (so if you forget to place the Client name as the first column in the Client’s grid before printing, the report will still sort it for you).

Detail band Before Print script has the following: " "

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
//we get the client’s name value so we can use it
string ClientName = Convert.ToString(GetCurrentColumnValue(“LT_O_Client”));

//suck out the first character of the client’s name string
string CurrentNameFirstCharacter=ClientName.Substring(0, 1);

//Check if first character has changed…
if (CurrentNameFirstCharacter != CurrentGroupCharacter)
{
//as has changed, than the new first character is put into the label field label4 and we increase the height of the detail band to fit this as well as the labels for the client and other fields
CurrentGroupCharacter = CurrentNameFirstCharacter;
label4.Text = CurrentGroupCharacter;
Detail.Height = 84;
label4.Visible = true;
label2.Top = 67;
label3.Top = 67;
}
else
{
//if not showing the header with the single character, than we tell it to not show the label4 and shrink it, as well as move up the other labels and change the height of the detailband
label4.Top = 9;
label4.Height = 17;
label4.Visible = false;
label2.Top = 9;
label3.Top = 9;
Detail.Height = 25;
}

}