Results 1 to 13 of 13

Thread: Which grid should I use

  1. #1

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Which grid should I use

    Hi Folks

    This is a general question not associated with any particular project but I'd like to get some opinions.

    I often find myself wanting to use a grid to display a result set and want to let users edit the contents of the grid directly. Every time I do this I find myself crowbarring the functionality of one grid or another to make it fit what I want to do.

    A datagrid seems the way to go on the surface but I find it to be inflexible and it's not great at handling calculated columns (ie a column that's calced from the db but doesn't map back to a specific individual column). I also find the whole concept of manipulating the datasource rather than the rows in the grid to be counter-intuitive, I'd rather detect a change event and then reflect the change back to the db or possibly write all changes back when the form closes.

    The flexgrid gives me the sort of control I'd like as I can manipulate columns, cells etc from code without needing to worry about the underlying datasource but it's not editable (I think - if it is then please tell me how). I've even ended up floating textboxes over the current cell to make it appear editable but that can be a major hassle and tends to fall apart as soon as scroll bars get involved.

    So what's my ideal grid? One where I can manipulate the contents and columns directly from code and handle user changes myself but which allows the user to actually chenge the contents of a cell. Any suggestions?

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Which grid should I use

    First blush would be the data grid. I use them in a few places, but I don't like them. I prefer the flexgrid. I have used the floating text box without any problem. However, the grid where I use that is a "fill in the data" type of grid, not 'change it as you go'. I just find I have more control over what is happening if I use the flex grid. I'm sure there will be many who disagree.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Which grid should I use

    Moved to General Developer.

    Actually, you can edit the flexgrid with some code.

    Based on what I read, you are pretty much restricting the question to the Grids available with VB, or do you want to expand the question into third party grid controls?
    Last edited by Hack; Jun 13th, 2005 at 10:35 AM.

  4. #4

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Which grid should I use

    I'm only interested in the basic vb grids.

    you can edit the flexgrid? could you point me at an example/tutorial? ...and thanks, you may be about to resove my longest standing vb gripe.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Which grid should I use

    The scroll issue you mention is the only one that we've encountered with floating a textbox or combobox on a flex grid cell...

    And it can be dealt with by restricting the scroll in the MSFLEXGRID scroll event - which is what we do. Basically you cannot scroll if the textbox would be cause to disappear off the grid.

    Once you have that logic for you program, it's set forever...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Which grid should I use

    I use the flexgrid myself. If you search for floating textbox, you will find many links. Here is one of them for you, with the method that I use.

    http://www.vbforums.com/showthread.p...oating+textbox

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Which grid should I use

    MSFlexgrid
    VB Code:
    1. Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
    2.  
    3.     With MSFlexGrid1
    4.         Select Case KeyAscii
    5.                
    6.             Case 8: 'IF KEY IS BACKSPACE THEN
    7.                 If .Text <> "" Then .Text = _
    8.                  Left$(.Text, (Len(.Text) - 1))
    9.             Case 13: 'IF KEY IS ENTER THEN
    10.                 Select Case .Col
    11.                     Case Is < (.Cols - 1):
    12.                         SendKeys "{right}"
    13.                     Case (.Cols - 1):
    14.                         If (.Row + 1) = .Rows Then
    15.                             .Rows = .Rows + 1
    16.                         End If
    17.                         SendKeys "{home}" + "{down}"
    18.                 End Select
    19.             Case Else
    20.                 .Text = .Text + Chr$(KeyAscii)
    21.                 'write your own keyascii Validations under
    22.                        'commented lines
    23.                 Select Case .Col
    24.                     Case 0, 1, 2:
    25.                         'if (your condition(s)) then
    26.                             'accept only charectors
    27.                         'Else
    28.                         '   keyascii=0
    29.                         'End If
    30.                     Case Else:
    31.                 End Select
    32.         End Select
    33.     End With
    34.  
    35. End Sub
    MSHFlexgrid
    VB Code:
    1. Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
    2.    Select Case KeyAscii
    3.         Case vbKeyReturn, vbKeyTab
    4.         'move to next cell.
    5.             With MSHFlexGrid1
    6.                 If .Col + 1 <= .Cols - 1 Then
    7.                     .Col = .Col + 1
    8.                 Else
    9.                     If .Row + 1 <= .Rows - 1 Then
    10.                         .Row = .Row + 1
    11.                         .Col = 0
    12.                     Else
    13.                         .Row = 1
    14.                         .Col = 0
    15.                     End If
    16.                 End If
    17.             End With
    18.         Case vbKeyBack
    19.             With MSHFlexGrid1
    20.                 'remove the last character, if any.
    21.                 If Len(.Text) Then
    22.                     .Text = Left(.Text, Len(.Text) - 1)
    23.                 End If
    24.             End With
    25.            
    26.         Case Is < 32
    27.        
    28.         Case Else
    29.             With MSHFlexGrid1
    30.                 .Text = .Text & Chr(KeyAscii)
    31.             End With
    32.     End Select
    33. End Sub

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Which grid should I use

    You also might want to check out this little tidbit by Martin Liss in the CodeBank section.

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Which grid should I use

    Hack - I've seen the "catch keypress" and put into current cell trick on the forum here before...

    But I'm sure my customers would not like the non-windows feel of that. COPY/PASTE - select/DELETE - using the arrows to move back into the text and correct or delete a typo.

    Have you used this before? What was the user reaction?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10

    Thread Starter
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Which grid should I use

    Wow, you go away for a couple of days and suddenly there's LOADS of info. Thanks guys.

    Unfortunately I always seem to need to put too much info in a grid to get away with disabling the scroll bars but catching the keypress looks like it'll do everything I want.

    I'm going to have a play with it for a few days and try to break it. If there's anything I can't do using this technique I'll let you know.

    Thx again

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Which grid should I use

    Quote Originally Posted by szlamany
    Hack - I've seen the "catch keypress" and put into current cell trick on the forum here before...

    But I'm sure my customers would not like the non-windows feel of that. COPY/PASTE - select/DELETE - using the arrows to move back into the text and correct or delete a typo.

    Have you used this before? What was the user reaction?
    In our commerical apps we use a third party grid that has far more flexibility than any grid that ships with VB. What I posted was some old code that I've used in corporate applications.

    You are right about your observations. I wouldn't be using that in commerical applications, but then, I can't imagine anyone writing a commerical application that would use a VB grid.

  12. #12
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Which grid should I use

    Quote Originally Posted by Hack
    ...but then, I can't imagine anyone writing a commerical application that would use a VB grid.
    We use the MSFlexGrid

    It does work for us - not sure what functionality other grids would offer that my customers would need...

    Although, now that you mention it, I don't like the MSFlexGrid sort capabilities or how much effort you have to go through to insure that a row is visible, the strange artifacts that appear on the grid when you make rows disappear...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Which grid should I use

    Quote Originally Posted by szlamany
    We use the MSFlexGrid

    It does work for us - not sure what functionality other grids would offer that my customers would need...

    Although, now that you mention it, I don't like the MSFlexGrid sort capabilities or how much effort you have to go through to insure that a row is visible, the strange artifacts that appear on the grid when you make rows disappear...
    Look into the Grid control made by Infragistics (formerly Sheridan). It is way cool, and it is pretty easy to use programmatically and provides all sorts of delightful features that customer really like. As a developer, I couldn't tell what the thing costs or what a multi-developer license is, but we use that in all of our applications where a grid would be used.

    (I was going to make some smart aleck remark about the commerical application of the MSFlexgrid, but then I thought - hey, you like szlamany, dont' bust his chops.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width