Using calendars with a table control

Discussion in 'Questions (Windows Mobile)' started by kolbe, Jan 24, 2008.

  1. kolbe

    kolbe Active Member Licensed User

    Hello all,

    I'm looking for a way to get a calendar to pop up near the cell that is clicked on a table. A quick way to enter a date in that cell. I know the cell that is clicked but can't find a way to get the x,y coordinates to position the calendar object near the cell. I can't even use the cell to calculate a position because the table is scrollable.

    Any ideas?
     
  2. klaus

    klaus Expert Licensed User

    Hello kolbe
    You can get the Top, Left, Width and Height values from your Table control and calculate the Top, Left values for the Calender object.

    Best regards
    Klaus
    Switzerland
     
  3. kolbe

    kolbe Active Member Licensed User

    Thanks Klaus but I'm afraid I still don't understand how this will allow me to position the calendar in reference to the cell selected. The idea is that the calendar appears where you click on the table. Knowing the cell doesn't help because the position on the screen is relative due to the fact that you can scroll the table... the cell could be anywhere within the visible part of the table. Basically I think I need a mousedown event for the table control that returns an x,y coordinate.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. klaus

    klaus Expert Licensed User

    Bonsoir Kolbe,
    I have never used dzt's dzEventsMagic library. Try it, other wise I see only the way below to calculate the optimum position.
    You know the selected cell
    so you what column and what row.
    Knowing the row height and the different column widths it is possible to know the cell coordinates.
    Then knowing the size of the calendar object, you can calculate it's optimum position.
    Je sais, ce n'est pas si simple mais pas si complqué non plus.
    Sorry thats our common language.
    It's not that simple but not that complicated either.

    Meilleures salutations
    Klaus
    Switzerland
     
  6. Cableguy

    Cableguy Expert Licensed User

    Is you app a desktop or a device app?
    If it is a device app, why try to pop-up a calendar? use a panael and meke it visible when you need it...
    The same aplies to the desktop, but in that case I can understand why you need to calculate the position, but is there any harm to always show the calendar control in the same position?...
    Still calculating the vertical position is fairly easy...
    imagine that your table is 50 lines high, and you only show 10..
    the minimum of the srollbar is 1 and the max is 50, but the step, if set to 5, gives you a way to know wich of the 10 visible lines were cliked...
    so on table select you can check wich line was selected, and (assuming they all have the same height) divide the used screen by the table, by the number of lines shown, minus the multiple of the height of the line index, minus the scrollbar step....pfuuuiuu.....

    it's better thought than put in words, but if you can visualize what i'm saying, it gets clearer...
     
  7. kolbe

    kolbe Active Member Licensed User

    Do we know the row height? I see a table.colwidth but that is it. No table.rowheight that I can see... table.height is the height of the whole table.

    Cableguy, I tried doing what you suggest but because the table scrolls, partial rows may be displayed and you don't get discreet places for your rows. Originally I had the calendar appearing the same spot but when actually using the program on a daily basis it get very annoying!

    I've tried the EventsMagic library and that works well. When the dzevent fires I store the x,y in a global. Then when the table.selectionchanged event fires (luckily after the dzevent) I know where to draw the calendar. There is still an issue if the cell is close to the edge of the screen but that can be worked out.

    Thanks for all the suggestions.
     
  8. klaus

    klaus Expert Licensed User

    Hello kolbe
    Yes there is no RowHeight in the table control, but the height is given and remains constant, the user cannot change it. So you can count its height in pixels and use this value. The ColumnWidth can be changed by the user so you must retreve them. But, as you say, the dzEventsMagic works well it is probably easyer to use it rather than to calculate the coordinates. The advatage of the calculation could be the fact that the calendar would be aligned with the cell and not at the mouse position somewhere in the cell, but this is a quetion of taste.
    The problem when the cell is near the right edge can be checked in looking if the mouse position x + Caledar1.With>Table.Width or the Form.Width and if yes set the x value to x= Table.Width-Caledar1.With
    If the calendar is near the bottom edge its the same but with the Heights y + Caledar1.Height>Form.Height and if yes set the y value to y= Form.Height-Caledar1.Height.
    Using Calender1.Height is OK you don't nead to take into account the height of the open calendar it opens below or above depending on the remaining space.

    I tried this calculation in one of my programs with a table, it works. If you are intersted in, I can post it to you.

    Best regards
    Klaus
    Switzerland
     
Loading...