|
-
Jun 13th, 2005, 10:06 AM
#1
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?
-
Jun 13th, 2005, 10:24 AM
#2
PowerPoster
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.
-
Jun 13th, 2005, 10:25 AM
#3
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.
-
Jun 13th, 2005, 11:06 AM
#4
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.
-
Jun 13th, 2005, 11:10 AM
#5
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...
-
Jun 13th, 2005, 11:12 AM
#6
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
-
Jun 13th, 2005, 11:13 AM
#7
Re: Which grid should I use
MSFlexgrid
VB Code:
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
With MSFlexGrid1
Select Case KeyAscii
Case 8: 'IF KEY IS BACKSPACE THEN
If .Text <> "" Then .Text = _
Left$(.Text, (Len(.Text) - 1))
Case 13: 'IF KEY IS ENTER THEN
Select Case .Col
Case Is < (.Cols - 1):
SendKeys "{right}"
Case (.Cols - 1):
If (.Row + 1) = .Rows Then
.Rows = .Rows + 1
End If
SendKeys "{home}" + "{down}"
End Select
Case Else
.Text = .Text + Chr$(KeyAscii)
'write your own keyascii Validations under
'commented lines
Select Case .Col
Case 0, 1, 2:
'if (your condition(s)) then
'accept only charectors
'Else
' keyascii=0
'End If
Case Else:
End Select
End Select
End With
End Sub
MSHFlexgrid
VB Code:
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn, vbKeyTab
'move to next cell.
With MSHFlexGrid1
If .Col + 1 <= .Cols - 1 Then
.Col = .Col + 1
Else
If .Row + 1 <= .Rows - 1 Then
.Row = .Row + 1
.Col = 0
Else
.Row = 1
.Col = 0
End If
End If
End With
Case vbKeyBack
With MSHFlexGrid1
'remove the last character, if any.
If Len(.Text) Then
.Text = Left(.Text, Len(.Text) - 1)
End If
End With
Case Is < 32
Case Else
With MSHFlexGrid1
.Text = .Text & Chr(KeyAscii)
End With
End Select
End Sub
-
Jun 13th, 2005, 01:49 PM
#8
Re: Which grid should I use
You also might want to check out this little tidbit by Martin Liss in the CodeBank section.
-
Jun 13th, 2005, 02:07 PM
#9
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?
-
Jun 15th, 2005, 04:03 AM
#10
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
-
Jun 15th, 2005, 07:17 AM
#11
Re: Which grid should I use
 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.
-
Jun 15th, 2005, 08:29 AM
#12
Re: Which grid should I use
 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...
-
Jun 15th, 2005, 11:44 AM
#13
Re: Which grid should I use
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|