A table with two columns, how to fit the colums in the table?

Discussion in 'Questions (Windows Mobile)' started by ghale, Jul 26, 2009.

  1. ghale

    ghale Active Member Licensed User

    Hello,
    I have a table that has two columns.
    When I fill the table, I want that the second column will be resized to stay in the table width.

    There are two cases:
    1. The rows are a lot so the table shows a vertical scrollbar
    2. The rows are few so I don't need the scrollbar
    How can I manage this?
    I've tried to do this:
    Code:
    [LEFT][FONT=Verdana][SIZE=2][COLOR=#010101][COLOR=#010101][FONT=Times New Roman]Table1.ColWidth("Col1")  = 100
    [/
    FONT][/COLOR][/COLOR][/SIZE][/FONT][FONT=Verdana][SIZE=2][COLOR=#010101][COLOR=#010101][FONT=Times New Roman]Table1.ColWidth("Col2")  = Table1.Width - [/FONT][/COLOR][/COLOR][/SIZE][/FONT][FONT=Verdana][SIZE=2][COLOR=#010101][COLOR=#010101][FONT=Times New Roman]Table1.ColWidth("Col1")[/FONT][/COLOR][/COLOR][/SIZE][/FONT][/LEFT]
    but of course this is not the correct way to accomplish this.

    I've read this in the forum, but I'm not sure if this will be a solution for me.

    Someone can help me, please?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can use the Door library to find the vertical scroll bar and horizontal scroll bar status.
    obj1 and obj2 are Objects from the Door library:
    Code:
    Sub GetScrollBarsProperties (tableName)
        obj1.FromControl(tableName)
        obj1.Value = obj1.GetProperty(
    "Controls")
        obj2.Value = obj1.GetProperty2(
    "Item"0)
        HScrollVisible = obj2.GetProperty(
    "Visible"'Horizontal scroll bar visible (true or false)
        HScrollHeight = obj2.GetProperty("Height"'Horizontal scroll height
        obj2.Value = obj1.GetProperty2("Item"1)
        VScrollVisible = obj2.GetProperty(
    "Visible"'Vertical scroll bar visible
        VScrollHeight = obj2.GetProperty("Width"'Vertical scroll bar width
    End Sub
     
  3. ghale

    ghale Active Member Licensed User

    I've put on Sub Globals of a module
    Code:
    obj1.New1(False)
    obj2.New1(
    False)
    Then,
    I've put
    Code:
    Sub GetScrollBarsProperties (tableName)
        obj1.FromControl(tableName)
        obj1.Value = obj1.GetProperty(
    "Controls")
        obj2.Value = obj1.GetProperty2(
    "Item"0)
        HScrollVisible = obj2.GetProperty(
    "Visible"'Horizontal scroll bar visible (true or false)
        HScrollHeight = obj2.GetProperty("Height"'Horizontal scroll height
        obj2.Value = obj1.GetProperty2("Item"1)
        VScrollVisible = obj2.GetProperty(
    "Visible"'Vertical scroll bar visible
        VScrollHeight = obj2.GetProperty("Width"'Vertical scroll bar width
        Msgbox(HScrollVisible & "." & HScrollHeight & "." & VScrollVisible & "." & VScrollHeight)
    End Sub
    So, when I call
    Code:
    GetScrollBarsProperties(tbEditor)
    I receive this error:
    Code:
    An error occurred on sub editor.frmeditor_show

    Line number: XXX

    GetScrollBarsProperties(tbEditor)
    Error description:
    Variable: editor.tbeditor was 
    not assigned any value.
    Continue?
    editor is the module name
    tbEditor is the table name

    What I can do???
     
  4. ghale

    ghale Active Member Licensed User

    All right, all right, I have to pass the table name in double quotes!

    Code:
    GetScrollBarsProperties("tbEditor")
    So all works!

    Thank you very much, Erel!
     
  5. ghale

    ghale Active Member Licensed User

    Mmmhh,
    I always receive False in Horizontal and Vertical scroll bar visible (True or False)

    It's correct???
    I have scrollbars!
     
  6. ghale

    ghale Active Member Licensed User

    :sign0161:

    I have to pass True in the constructor for Door object, according to documentation:
     
  7. ghale

    ghale Active Member Licensed User

    Ok, there a strange "issue"

    The table width is 240
    The first column width is 192
    The second colum width is 48

    So: 192 + 48 = 240, but...

    I have to subtract 4 to to first or second colums to avoid horizontal scrollbar!

    Why 4?

    Maybe I have to consider:
    • 1 pixel border from left side of first column
    • 1 pixel border from rigth side of first column
    • 1 pixel border from left side of second column
    • 1 pixel border from rigth side of second column
    ??
     
  8. ghale

    ghale Active Member Licensed User

    I've edited this post to make it clear the problem:

    I have a 240 width table,
    I want two colums.

    I have only the second column width fixed,
    the first colums must adapt his width dinamically if vertical scrollbar is visible or not.

    I use this code:
    Code:
    Public Sub FixScrollBars
    obj1.FromControl(
    "tbEditor")
        obj1.Value = obj1.GetProperty(
    "Controls")
        
        obj2.Value = obj1.GetProperty2(
    "Item"0)
        
    'HScrollVisible = obj2.GetProperty("Visible") 'Horizontal scroll bar visible (True o False)
        'HScrollHeight = obj2.GetProperty("Height") 'Horizontal scroll height
        
        obj2.Value = obj1.GetProperty2(
    "Item"1)
        VScrollVisible = obj2.GetProperty(
    "Visible"'Vertical scroll bar visible
        VScrollWidth = obj2.GetProperty("Width"'Vertical scroll bar width

        
    If VScrollVisible = True Then
            tbEditor.ColWidth(
    "Word") = tbEditor.Width - priorityColumnWidth - VScrollWidth
        
    Else
            tbEditor.ColWidth(
    "Word") = tbEditor.Width - priorityColumnWidth
        
    End If
    End SUb
    To calculate first column width, I do:

    table.width - second_column.widht - Vscrollwidth if scrollbar is visible
    table.width - second_column.widht if scrollbar is NOT visible

    In both cases, I've seen that the first column has ALWAYS 192 as width dimension.
    It seems that tbEditor.ColWidth("Word") assignment is not considered!

    Info: I call FixScrollBars function from another module (the Main module), after calling the .Show method for the form that contains the table.
    I do this because If I call FixScrollBars in the Show method of the form that has the table, I've noticed that the scrollbars are not detected, infact VScrollVisible is always False!

    Someone has a solution?
     
    Last edited: Jul 26, 2009
  9. ghale

    ghale Active Member Licensed User

    No idea about this issue?
     
  10. agraham

    agraham Expert Licensed User

    If you take a screen shot and blow it up you can see that the Width of a table includes the two pixel wide vertical borders at each side so the display area of a Table is four pixels less than Width property. The same is true for the Height.
     
  11. ghale

    ghale Active Member Licensed User

    Ok agraham, thanks.
    I've thinked that the pixels was added for something about borders of the table.

    But I've seen that if I add rows to table and dinamically calculate the first column width and set it in the frm_Show method, when the form is shown on the screen, the column width I set is ignored!
    This happen only if there is a vertical scrollbar.

    Someone can reproduce this issue?
     
  12. agraham

    agraham Expert Licensed User

    Why don't you post a simple app that displays the problem?
     
  13. ghale

    ghale Active Member Licensed User

    I've attached an example.

    You'll noticed that the condition:
    Code:
    If VScrollVisible = True Then
    will never be true because of the table is not showed on the screen (or at least, this is what I think).

    How I can determine if VScrollVisible = True ?

    So for now I've used a ForceFix sub,
    to assign a forced value to column according to row number contained in the table.

    I've added a button. If I press it when the form is visible, the columns are correctly calculated and set.
     
    Last edited: Jul 27, 2009
  14. agraham

    agraham Expert Licensed User

    Firstly this fails when optimised compiled because of a bug - see http://www.basic4ppc.com/forum/bug-reports/4645-comparison-fails-when-optimised-compiled.html. A workaround is

    If VScrollVisible = True OR VScrollVisible = "True" Then


    I think the main "problem" is probably that the visibility of the scroll bars is decided when the Listbox is painted and you are trying to determine this in the Forms' first Show event at which time I don't think the Listbox has been painted yet and so does not know whether it needs scroll bars or not.

    You can, rather inelegantly, use a one shot Timer to get around this. The Timer code only runs when the Form and its controls are all finished painting and the flow of execution exits App_Start and starts to process messages in the Forms' message loop.
    Code:
    Sub App_Start
       frmMain.Show
       Timer1.Interval = 
    1
       Timer1.Enabled = 
    True
    End Sub

    Sub Timer1_Tick
       Timer1.Enabled = 
    False
       FixScrollBars(
    "tbEditor")
    End Sub
     
  15. ghale

    ghale Active Member Licensed User

    Hello agraham, yesterday night I've solved the issue in the way you write here!

    Thanks for your help,
    bye,
    Pierluigi
     
  16. ghale

    ghale Active Member Licensed User

    I've seen that compiling with Device (Auto Scale) Exe,
    the Vertical Scrollbar Width is 13 on QVGA and 26 on VGA.

    So, using the dynamic resize of column width, on VGA device my first column not fit exactly the space, so the second column has a 13 pixels distance from the vertical scrollbar!

    If I (only as a test) to the FixScrollbars add 13 to the calculated width, the two columns have precise width.

    There is a way to avoid this? :sign0085:
     
  17. agraham

    agraham Expert Licensed User

    Help->MainHelp->Keywords->General->ScreenScaleY

    width = calculatedWidth + 13 * (ScreenScaleY -1)
     
  18. ghale

    ghale Active Member Licensed User

    Thank you very much, agraham!
    I've used ScreenScaleY to dinamically calculate positions.
    Thanks.
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    You should use ScreenScaleX instead of ScreenScaleY as you are checking the horizontal scaling and not the vertical scaling (both equals 2 on regular VGA devices).
    Can you please upload a small program with the columns adjusting code? I guess that this code may be useful for many users.
     
  20. ghale

    ghale Active Member Licensed User

    :sign0027:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice