2

I want to create an application that displays EPG, as in this image: http://gonedigital.net/wp-content/uploads/SonyEPG.jpg

I need a control to display the timeline. I considered using a datagridview, but I think it won't be appropriate since the column sizes can't be set for each row. Is there a custom cotrol that can be used? If not are there any suggestions on how to start? Thanks

Edit:

I've used the TableLayoutPanel and it worked properly for small amount of data. Foe larger data it be became too small. I searched and found SourceGrid which was very fast and flexible.

Jerry
  • 4,258
  • 3
  • 31
  • 58
  • 1
    A TableLayoutPanel might work. You can set up columns/rows and make controls span multiple columns. – Idle_Mind Oct 16 '13 at 14:30
  • Thanks! Can you show me an example of how to add a label to two adjacent cells in the table? – Jerry Oct 17 '13 at 13:20

1 Answers1

2

Sure...try this TableLayoutPanel example out with a new form. Ignore the colors as they are nasty; focus instead on the grid layout and how the Labels span columns. This is just the header plus the first three rows. Resize the WIDTH of the form and note how the proportions are maintained: Television Guide via a TableLayoutPanel

public partial class Form1 : Form
{

    private TableLayoutPanel grid = new TableLayoutPanel();

    public Form1()
    {
        InitializeComponent();

        grid.RowCount = 9;
        for (int i = 1; i <= grid.RowCount; i++)
        {
            grid.RowStyles.Add(new RowStyle(SizeType.Percent, 42)); // all the same percent, the value doesn't matter
        }
        grid.ColumnCount = 16;
        for (int i = 1; i <= grid.ColumnCount; i++)
        {
            grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 42)); // all the same percent, the value doesn't matter
        }
        grid.Dock = DockStyle.Fill;
        this.Controls.Add(grid);

        this.BackColor = Color.Black;
        ExampleGrid();
    }

    private void ExampleGrid()
    {
        grid.Controls.Clear();

        AddEntry("Today", 0, 1, 3, Color.White, Color.Black, false);
        AddEntry("| 14:00", 0, 4, 3, Color.White, Color.Black, false);
        AddEntry("| 14:30", 0, 7, 3, Color.White, Color.Black, false);
        AddEntry("| 15:00", 0, 10, 3, Color.White, Color.Black, false);
        AddEntry("| 15:30", 0, 13, 3, Color.White, Color.Black, false);

        AddEntry("050", 1, 0, 1, Color.White, Color.Black, false);
        AddEntry("BBC HD", 1, 1, 3, Color.White, Color.Black, false);
        AddEntry("Mary Poppins", 1, 4, 8, Color.Black, Color.White, true);
        AddEntry("Dustbin Baby -->", 1, 12, 4, Color.White, Color.LightGray, true);

        AddEntry("051", 2, 0, 1, Color.White, Color.Black, false);
        AddEntry("ITV1 HD", 2, 1, 3, Color.White, Color.Black, false);
        AddEntry("Rosemary and Thyme", 2, 4, 6, Color.White, Color.Gray, true);
        AddEntry("Agatha Christie's Poirot -->", 2, 10, 6, Color.White, Color.LightGray, true);

        AddEntry("052", 3, 0, 1, Color.White, Color.Black, false);
        AddEntry("Channel 4 HD", 3, 1, 3, Color.White, Color.Black, false);
        AddEntry("The Green Berets", 3, 4, 5, Color.White, Color.Gray, true);
        AddEntry("Coach Trip", 3, 9, 3, Color.White, Color.LightGray, true);
        AddEntry("Countdown -->", 3, 12, 4, Color.White, Color.LightGray, true); 

        // ... etc ...
    }

    private void AddEntry(string text, int row, int col, int columnSpan, Color foreColor, Color backColor, bool border)
    {
        Label lbl = new Label();
        lbl.Text = text;
        lbl.AutoSize = false;
        lbl.AutoEllipsis = true;
        lbl.ForeColor = foreColor;
        lbl.BackColor = backColor;
        lbl.Dock = DockStyle.Fill;
        lbl.BorderStyle = border ? BorderStyle.FixedSingle : BorderStyle.None;
        lbl.TextAlign = ContentAlignment.MiddleLeft;
        grid.Controls.Add(lbl, col, row);
        grid.SetColumnSpan(lbl, columnSpan);
    }

}
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • Thank you very much! This looks great. I have two questions if you please: 1. Does TableLayoutPanel has an advantage over the DataGridView here. 2. How to handle more events to the right? Can it be scrolled? Thanks – Jerry Oct 17 '13 at 15:35
  • I haven't used the DataGridView much...not sure. Scrolling: Either repopulate the entire grid to "shift" everything, or make the TableLayoutPanel have many more columns and make it wider but place it INSIDE a Panel that has AutoScroll set to true. – Idle_Mind Oct 17 '13 at 15:54
  • Thanks! I had to change `SizeType.Percent` to `Absolute` as well. I also tried without using a panel to set `AutoScroll`of the `TableLayoutPanel` to true and it worked. Thanks again. – Jerry Oct 17 '13 at 16:06
  • Sorry, I have another question. Is it possible to make the labels adjacent without leaving space between them? Thanks – Jerry Oct 17 '13 at 16:16
  • 1
    That spacing in between them is controlled by the **Margin() Property** I think. – Idle_Mind Oct 17 '13 at 16:20
  • Exactly! I added lbl.Margin = new Padding(0); and spaces were removed. Thank you very much for your help! – Jerry Oct 17 '13 at 16:24