Click to See Complete Forum and Search --> : Grid or Text Boxes ?


Dr_Michael
October 20th, 1999, 03:26 AM
I want to create a table where the user can insert some values (nothing to do with database). Which is the better way to use: DBGrid (unbound mode) or many text boxes near to each other as a control array?

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 03:54 AM
I'd use a DBGrid.
Why?
with textboxes you'd probably have to implement scrolling(keyboard AND mouse) very soon.

Even if your app has nothing to do with a database I'd still use bound mode and use a disconnected recordset (as I have been trying to advertise for many many months in this forum :-)).

Dr_Michael
October 20th, 1999, 04:04 AM
Ok I'll try use your way. Can you tell me how to?
(although you may told me again but I don't remember...).
Have in mind that I want to satisfy these:
1. The user can delete any row, by selecting and pressing delete.
2. The user can add a row at the end.
3. The values that inserts on grid must be under some rules (I will build a knowledge based system-grid with many rules, checking and control)
Having all these in mind could you post the right code for it?
(The size of the grid will be at about 18 columns and 500 rows...)
Thank you Lothar!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 04:28 AM
Unfortunately, I do not have the time to write your application :-)
requirements 1 and 2 are properties of the dbgrid. It's easy to set allowAddnew and allowdelete to true.

to implement validation logic you can do this in your save logic (probably triggered from a button or menu).

here is a small sample to use a dbgrid in bound mode without a database.


Dim r as ADOR.Recordset
set r = new ADOR.Recordset

r.Fields.Append "firstfield", adInteger
r.Fields.Append "secondfield", adInteger
r.CursorType = adOpenDynamic
r.Open
r.AddNew
r.Fields(0).Value = 1
r.Fields(1).Value = 2
r.AddNew
r.Fields(0).Value = 3
r.Fields(1).Value = 4
set g.DataSource = r



by setting AllowAddNew and AllowDelete to True, I was able to add new rows and delete selected rows.

This has been tested unter
NT4 SP 5
VB 6 SP3

Good luck.

Lothar Haensler
October 20th, 1999, 04:29 AM
One more point. I didn't even have to add the complete ADO reference, but only the small ADOR recordset library!

Dr_Michael
October 20th, 1999, 05:04 AM
The right code sould be this:

Dim r as ADOR.Recordset
set r = new ADOR.Recordset
r.Fields.Append "firstfield", adInteger
r.Fields.Append "secondfield", adInteger
r.CursorType = adOpenDynamic
r.Open
r.AddNew
r.Fields(0).Value = 1
r.Fields(1).Value = 2
r.AddNew
r.Fields(0).Value = 3
r.Fields(1).Value = 4
set g = r.DataSource



Right? But what is g?
How to define it?
Thanx Lothar!!!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 06:07 AM
I don't see what makes you code "righter" than mine, since mine worked.
Anyway, "g" is the name of my dbgrid object on the form. I'm lazy, that's why all my controls have short names :-)

Dr_Michael
October 20th, 1999, 07:58 AM
Only the last line of your code was inversed!
And this is not my code... All is yours!!!
So, thank you a lot.
Rating comes soon...

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Dr_Michael
October 20th, 1999, 08:07 AM
set DBGrid1 = r.DataSource



Are you sure? This doesn't work...

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 08:37 AM
I'm confused. I guess you are right.

Dr_Michael
October 20th, 1999, 08:58 AM
Please can you post me the right code, because I am very curious to explore your way...
It seems very simple to be true!!!
:-)

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 09:00 AM
Set YourGridNameGoesHere.DataSource = r
should do it.

Dr_Michael
October 20th, 1999, 09:10 AM
It displays the following message:
"Class doesn't support Automation or does not support expected interface"
??? :-o

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 09:13 AM
Looks like we are using different grids?!
I have already thrown away my sample project. Try using one of the grids that supports ADO data binding.

Dr_Michael
October 20th, 1999, 09:22 AM
I use:
Microsoft Data Bound Grid Control 5 (SP3). Is that the same with yours?
Yes, it has datasource property!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 09:30 AM
I use VB 6, maybe that's the source of our misunderstandings. I'm afraid my solution won't work in VB 5.

Dr_Michael
October 20th, 1999, 09:34 AM
I use also VB6 SP3 on Win98.
Where is the difference?
Please copy paste the code to a new project and test it again (last line has definetely a problem)
I am new in Vb but not beginner (1 year experience). I can understand if a line of code is wrong or if it doesn't work because of my system. Thanx and sorry for being continued...!
;-)

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 09:45 AM
OK, here we go again:
the code

Dim r as ADOR.Recordset
set r = new ADOR.Recordset

r.Fields.Append "firstfield", adInteger
r.Fields.Append "secondfield", adInteger
r.CursorType = adOpenDynamic
r.Open
r.AddNew
r.Fields(0).Value = 1
r.Fields(1).Value = 2
r.AddNew
r.Fields(0).Value = 3
r.Fields(1).Value = 4
set g.DataSource = r



the component: "Microsoft Datagrid Control 6.0 (SP3) (OLEDB)" (named "g")
references: "Microsoft ActiveX Data Objects Recordset 2.1 Library"

(the sample still works)
based on
- NT 4 SP 5
- VB 6 SP 3

Dr_Michael
October 20th, 1999, 10:01 AM
This is the best and simplest code ever seen!!!
Congratulations Lothar!!!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 20th, 1999, 10:03 AM
Thanks. IMHO this feature (Recordsets without a database connection) is widely ignored by the VB developer community, although it's the best thing in VB 6 that I have found so far.

Bruno
October 20th, 1999, 06:18 PM
Hi,
If you are still interested in DBGrid 5.0 (unbound mode) I can mail you a sample.
Code is long & not elegant, but it is easy to modify it - and it doesn't require ADO (mdac_type is over 6 MB)

BrewGuru99
October 20th, 1999, 09:38 PM
It's incredable! It's Awsome! I wish I thought of it!!!



Brewguru99

Dr_Michael
October 21st, 1999, 03:51 AM
Ok, just post it here or send it via email to me...
Thanx!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Dr_Michael
October 21st, 1999, 04:01 AM
Well, what comes next Lothar:
I created the table as you said...
One idea: Could it be good to create a control array of text boxes equal with the number of columns of grid. So when the user wants to enter data to the grid to have only to enter the data on the text boxes and display on the grid. If the user wants to edit old data, with double click the whole row will be displayed on text boxes.
Of course there will be two buttons, ok and cancel.
Is it better or not? And I ask this because I want to have complete control on the values entered...!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Ravi Kiran
October 21st, 1999, 04:07 AM
TO restart the whole issue: How about one of these Flex-Grids!:-)

RK

Lothar Haensler
October 21st, 1999, 04:18 AM
my experience with the various grids is limited.
Thus, I'd say your approach sounds reasonable.
You might be able to get complete control over the editing process within the grid. But, that could be difficult. it's probably easier to use textboxes.

Here we go again: Ravi has suggested that you use a flexgrid. Well, if you do not allow editing within the DBGrid you might as well use a flexgrid.

Dr_Michael
October 21st, 1999, 04:48 AM
My dear friend, thanx to all of you here, I have many ideas in my mind...
I will choose the final with these criteria:
1. Not too many resources (memory)
2. I want complete control of all the values entered because I'm going to create an expert system (knowledge based) in order to program a robot!
Any ideas?
Tell me about ms flex grid...
thanx!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Dr_Michael
October 21st, 1999, 04:51 AM
...and tell me your opinion about control boundaries!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Ravi Kiran
October 21st, 1999, 06:11 AM
I had done this thing with MS-Flex Grid. (VB 5.0)

It displays the values in a Grid. User can edit the values "in-line" by double clicking any cell. Since Flex-grid doesn't allow automatic editing, unlike DBGrid, you need to do some decent amnt of programing to capture all modes of exit from "Editing" mode, like scrolling etc.

The it will also allow editing of a row data, in another set of Text boxes below. So when the user dbl clicks on the Row-x, Col-0, the values will be updated into those text boes, and the focus moves there and he can only escape from that mode by save/cancel stuff. Same set of routines work for data-validation either in-line or off-line editing. Well that's broadly the project:-)

-- I guess, MsFlexGrid will take more memory than DBGrid. It supports lot more stuff, like colors, pictures etc. So even if you dont use them, it may still be more memory hungry than DB grid.

RK

Dr_Michael
October 21st, 1999, 06:25 AM
Well, guys, we have 3 grids:

1. My solution with DBGrid in unbound mode.
2. Lothar's solution with DataGrid and ADOR
3. Ravi's solution with MSFlexgrid.

Which is the suitable for what I want?
I repeat my scopes:
1. Not to eat enough resources (memory)
2. Large size (500 rows - 13 columns)
3. Complete control of values entered
4. Easy interface
5. Many, many rules -> knowledge based system

Thanx all!

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 21st, 1999, 06:37 AM
That's easy: my solution is the best! :-)
just kidding.
1. resources: if you had NT you could use the task manager to find the true resource usage without guessing.
I doubt, though, that resources should be a real concern.

2. that's not really a "large" size. all 3 approaches can handle that easily

3. use the text box approach and be totally independent of the smartness of the underlying grid

4. see 3

5. that's not a problem of the grids.

Dr_Michael
October 21st, 1999, 06:58 AM
Is it possible to post here the whole code you have done (with double clicks, scrolling etc...)?

Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Dr_Michael
October 21st, 1999, 07:55 AM
If I use your solution with DataGrid, in addition with text boxes, then do I have to use ADOR? I mean will I use recordsets? Or can I enter values on text boxes and just display them on grid?
Still confused...


Michael Vlastos
Automation Engineer
Company Modus SA
Development Department
Athens, Greece

Lothar Haensler
October 21st, 1999, 07:59 AM
that's what I suggested.
My solution is targeted towards minimal programming effort. That's why I suggested data-binding and "stand-alone" recordsets.
Yes, you'll need ADO. So what?! ADO has become part of the OS already via several service Packs (at least as far as NT is concerned).