data grids/ms flex grids 
Author Message
 data grids/ms flex grids

Hi

I am struggling with databases again in VB6. If I use the msflex grid
control I can display data from an Access 97 db, but can't update it. If I
use a data grid control I don't seem to be able to open the data up into it,
without using a data control (adodc). I don't want to use the adodc.

Preferably I would want to use the flex grid, does any one know of a way of
being able to update cells in this grid.

Jules



Tue, 27 Sep 2005 23:27:09 GMT  
 data grids/ms flex grids


Quote:
> Hi

> I am struggling with databases again in VB6. If I use the msflex grid
> control I can display data from an Access 97 db, but can't update it. If I
> use a data grid control I don't seem to be able to open the data up into
it,
> without using a data control (adodc). I don't want to use the adodc.

> Preferably I would want to use the flex grid, does any one know of a way
of
> being able to update cells in this grid.

> Jules

The data controls are very slow, I never use them either. The only thing
holding you back is getting the data into the flex grid. This can be
accomplished by using hidden controls to capture the input. Here is an
example of how to do this:

First setup the Form add the MSHFlexGrid(grdData) control and a
textbox(txtData).

Add the following code

    Private Sub Form_Load()
        'This will hide the textbox until we are ready to use it.
        txtData.Visible = false
    End Sub

Use whatever routine you like to load the Grid.

Private Sub grdData_DblClick()
' This will show the text box in the cell that was double clicked
    With txtData
          .Width = grdData.CellWidth
          .Left = grdData.CellLeft + m_Grid.Left
          .Top = grdData.CellTop + m_Grid.Top
          .Text = grdData.Text
          .Visible = True
          .SelStart = 0
          .SelLength = Len(.Text)
          .SetFocus
        End With
End Sub

Private Sub txtData_KeyPress(KeyAscii As Integer)

   'This will hide the textbox and update the cell with text from the text
box when the enter key is pressed

  Select Case KeyAscii
    Case vbKeyReturn
      KeyAscii = 0
      grdData.TextMatrix(grdData.RowSel, grdData.BandColIndex) =
txtData.Text
      txtData.Visible = False
      If grdData.BandColIndex + 1 > grdData.Cols - 1 Then
        grdData.Col = 0
        If grdData.RowSel + 1 > grdData.Rows - 1 Then grdData.Row = 0
        grdData.Row = grdData.RowSel + 1
      End If
      grdData.Col = grdData.BandColIndex + 1

    Case vbKeyEscape
      txtData.Visible = False

    Case vbKeyTab
      txtData.Visible = False

  End Select

You can then use your routine to update the database from the grid. There is
a lot more to do. As you will see once you start using it, but his should
get you started.
I hope this helps.



Thu, 29 Sep 2005 01:23:42 GMT  
 data grids/ms flex grids

Quote:

> Hi

> I am struggling with databases again in VB6. If I use the msflex grid
> control I can display data from an Access 97 db, but can't update it.
> If I use a data grid control I don't seem to be able to open the data
> up into it, without using a data control (adodc). I don't want to use
> the adodc.

> Preferably I would want to use the flex grid, does any one know of a
> way of being able to update cells in this grid.

> Jules

Julia,

Why not double-click (or select a row, then click Edit) the row and load a
form which display all the items in a way which you can edit (ie using
textboxes, etc.)?

I usually put the primary key in the first column and make it zero width.

Double click on the row, identify the row, get the primary key, pass it to
your edit form which loads the data to be edited (if primary key is zero
we're adding a new record). Save the changes to the database, update the
grid and close the edit form.

HTH



Thu, 29 Sep 2005 11:45:48 GMT  
 data grids/ms flex grids
I agree with Jason's approach as I don't like grid-based editing. But,
if you really want to do it with a DataGrid, you can do it by binding
directly to an ADO recordset like this:

0. Dim a recordset in the form's General Declarations.
1. Open the recordset.
2. Set the grid's DataSource property to be the recordset.

No Data Control required! There are three methods of handling the
database updating:

0. Use a connected recordset so the updates occur when the user moves
off the row they have altered or added. This can be confusing to the
user as it's not very clear whether their updates have really
happened. Also there's no way to offer a Cancel button because their
changes have already been posted.

1. Use a disconnected recordset and then reconnect it and call its
UpdateBatch method to get all the changes posted. I have a {*filter*}
feeling that ADO will update all the rows it can but, if some of them
won't go because of things like index or foreign key constraints, you
end up with some changes saved and others not. Then you have to go
through the recordset and use the Status property to identify the
offending rows and tell the user what the problem was. Also the users
need the relevant permissions on the underlying tables, which is fine
for Access but the technique does not scale to SQL Server. (At least,
it will work but it will not make you popular with the DBAs.)

2. Use a disconnected recordset and manually go through the rows. If
the Status property indicates the row has been added, edited or
deleted in the recordset execute the relevant code to update the
database accordingly. This a lot of work.

As you can see, it's quite a job to implement scalable and robust grid
editing. Much better to show a read-only grid and use a modal dialogue
to edit one record at a time.

Quote:


> > Hi

> > I am struggling with databases again in VB6. If I use the msflex grid
> > control I can display data from an Access 97 db, but can't update it.
> > If I use a data grid control I don't seem to be able to open the data
> > up into it, without using a data control (adodc). I don't want to use
> > the adodc.

> > Preferably I would want to use the flex grid, does any one know of a
> > way of being able to update cells in this grid.

> > Jules

> Julia,

> Why not double-click (or select a row, then click Edit) the row and load a
> form which display all the items in a way which you can edit (ie using
> textboxes, etc.)?

> I usually put the primary key in the first column and make it zero width.

> Double click on the row, identify the row, get the primary key, pass it to
> your edit form which loads the data to be edited (if primary key is zero
> we're adding a new record). Save the changes to the database, update the
> grid and close the edit form.

> HTH



Fri, 30 Sep 2005 18:24:18 GMT  
 data grids/ms flex grids
All in thread,

Directly editing the cell data is easier to understand and involves
less clicks...also the end-user can start typing right away.

Aditya



Fri, 30 Sep 2005 21:53:12 GMT  
 data grids/ms flex grids

Quote:

> All in thread,

> Directly editing the cell data is easier to understand and involves
> less clicks...also the end-user can start typing right away.

> Aditya

If you need checkboxes, comboboxes, multiline text boxes, etc, you're going
to have "fun" writing the code to line up these controls on the grid cell to
be edited. It's even more "fun" trying to get it to work when you need to
resize the form & grid. So it's a lot easier (perhaps even necessary) to
purchase a grid that does all this for you - if you insist on editing within
the grid.

Or, you can create a form - easily and for free (and access it with one
extra click).

Jason



Sat, 01 Oct 2005 22:26:49 GMT  
 data grids/ms flex grids


Quote:
> I agree with Jason's approach as I don't like grid-based editing. But,

So you don't like Excel?

Quote:
> if you really want to do it with a DataGrid, you can do it by binding
> directly to an ADO recordset like this:

> 0. Dim a recordset in the form's General Declarations.
> 1. Open the recordset.
> 2. Set the grid's DataSource property to be the recordset.

> No Data Control required! There are three methods of handling the
> database updating:

> 0. Use a connected recordset so the updates occur when the user moves
> off the row they have altered or added. This can be confusing to the
> user as it's not very clear whether their updates have really
> happened. Also there's no way to offer a Cancel button because their
> changes have already been posted.

> 1. Use a disconnected recordset and then reconnect it and call its
> UpdateBatch method to get all the changes posted. I have a {*filter*}
> feeling that ADO will update all the rows it can but, if some of them
> won't go because of things like index or foreign key constraints, you
> end up with some changes saved and others not. Then you have to go
> through the recordset and use the Status property to identify the
> offending rows and tell the user what the problem was. Also the users
> need the relevant permissions on the underlying tables, which is fine
> for Access but the technique does not scale to SQL Server. (At least,
> it will work but it will not make you popular with the DBAs.)

This is totally unworkable on any platform with more than
one user. If you even mention recordset updates in our shop, you will be
banned from coding.

Quote:
> 2. Use a disconnected recordset and manually go through the rows. If
> the Status property indicates the row has been added, edited or
> deleted in the recordset execute the relevant code to update the
> database accordingly. This a lot of work.

> As you can see, it's quite a job to implement scalable and robust grid
> editing. Much better to show a read-only grid and use a modal dialogue
> to edit one record at a time.

Maybe this should read: this is much better because it is my idea or, this
much better because this is what I understand.
Quote:




- Show quoted text -

Quote:

> > > Hi

> > > I am struggling with databases again in VB6. If I use the msflex grid
> > > control I can display data from an Access 97 db, but can't update it.
> > > If I use a data grid control I don't seem to be able to open the data
> > > up into it, without using a data control (adodc). I don't want to use
> > > the adodc.

> > > Preferably I would want to use the flex grid, does any one know of a
> > > way of being able to update cells in this grid.

> > > Jules

> > Julia,

> > Why not double-click (or select a row, then click Edit) the row and load
a
> > form which display all the items in a way which you can edit (ie using
> > textboxes, etc.)?

> > I usually put the primary key in the first column and make it zero
width.

> > Double click on the row, identify the row, get the primary key, pass it
to
> > your edit form which loads the data to be edited (if primary key is zero
> > we're adding a new record). Save the changes to the database, update the
> > grid and close the edit form.

> > HTH



Sat, 01 Oct 2005 19:25:27 GMT  
 data grids/ms flex grids


Quote:

> > All in thread,

> > Directly editing the cell data is easier to understand and involves
> > less clicks...also the end-user can start typing right away.

> > Aditya

> If you need checkboxes, comboboxes, multiline text boxes, etc, you're
going
> to have "fun" writing the code to line up these controls on the grid cell
to
> be edited. It's even more "fun" trying to get it to work when you need to
> resize the form & grid. So it's a lot easier (perhaps even necessary) to
> purchase a grid that does all this for you - if you insist on editing
within
> the grid.

All this is very easy to do, and with the proper design you can use one form
to edit all your tables, instead of having a form for each table.

- Show quoted text -

Quote:

> Or, you can create a form - easily and for free (and access it with one
> extra click).

> Jason



Sun, 02 Oct 2005 15:43:51 GMT  
 data grids/ms flex grids
Robert, did you get out of bed on the wrong side this morning or
something?


Quote:


> > I agree with Jason's approach as I don't like grid-based editing. But,
> So you don't like Excel?

I don't see what your point is.

Quote:

> > if you really want to do it with a DataGrid, you can do it by binding
> > directly to an ADO recordset like this:

> > 0. Dim a recordset in the form's General Declarations.
> > 1. Open the recordset.
> > 2. Set the grid's DataSource property to be the recordset.

> > No Data Control required! There are three methods of handling the
> > database updating:

> > 0. Use a connected recordset so the updates occur when the user moves
> > off the row they have altered or added. This can be confusing to the
> > user as it's not very clear whether their updates have really
> > happened. Also there's no way to offer a Cancel button because their
> > changes have already been posted.

> > 1. Use a disconnected recordset and then reconnect it and call its
> > UpdateBatch method to get all the changes posted. I have a {*filter*}
> > feeling that ADO will update all the rows it can but, if some of them
> > won't go because of things like index or foreign key constraints, you
> > end up with some changes saved and others not. Then you have to go
> > through the recordset and use the Status property to identify the
> > offending rows and tell the user what the problem was. Also the users
> > need the relevant permissions on the underlying tables, which is fine
> > for Access but the technique does not scale to SQL Server. (At least,
> > it will work but it will not make you popular with the DBAs.)

> This is totally unworkable on any platform with more than
> one user. If you even mention recordset updates in our shop, you will be
> banned from coding.

I was not exactly recommending it. Just going through the options. I
agree that the multi-user aspect is also another reason not to do it
this way.

Quote:
> > 2. Use a disconnected recordset and manually go through the rows. If
> > the Status property indicates the row has been added, edited or
> > deleted in the recordset execute the relevant code to update the
> > database accordingly. This a lot of work.

> > As you can see, it's quite a job to implement scalable and robust grid
> > editing. Much better to show a read-only grid and use a modal dialogue
> > to edit one record at a time.

> Maybe this should read: this is much better because it is my idea or, this
> much better because this is what I understand.

What's with the attitude? The original poster wanted to know about
editing in grids. I went through the other options as I see them and
pointed out why each one is not too good. Then I recommended a
technique that is widely regarded as a better way of doing it. It's
not my own idea and I think I've demonstrated a reasonable grasp of
other ways of doing it. What's your problem?

- Show quoted text -

Quote:




> > > > Hi

> > > > I am struggling with databases again in VB6. If I use the msflex grid
> > > > control I can display data from an Access 97 db, but can't update it.
> > > > If I use a data grid control I don't seem to be able to open the data
> > > > up into it, without using a data control (adodc). I don't want to use
> > > > the adodc.

> > > > Preferably I would want to use the flex grid, does any one know of a
> > > > way of being able to update cells in this grid.

> > > > Jules

> > > Julia,

> > > Why not double-click (or select a row, then click Edit) the row and load
>  a
> > > form which display all the items in a way which you can edit (ie using
> > > textboxes, etc.)?

> > > I usually put the primary key in the first column and make it zero
>  width.

> > > Double click on the row, identify the row, get the primary key, pass it
>  to
> > > your edit form which loads the data to be edited (if primary key is zero
> > > we're adding a new record). Save the changes to the database, update the
> > > grid and close the edit form.

> > > HTH



Sun, 02 Oct 2005 17:21:05 GMT  
 data grids/ms flex grids
My point is:
It seems everyone is trying to get her to redesign her app. She asked a
specific question about a specific problem, and I gave her a specific
answer. Then everyone tries to get her to redesign her app. This may not be
possible.

If she has been handed a request to implement a program with specific
interface requirements, she goes back to the project manager and states I
have changed the interface requirements to something I was told was better,
then guess what, it is not going to get implemented, and she may get
reprimanded. This is a good way to be a jr. programmer for quite some time.
This is also a pet peeve I have, and why I rarely use newsgroups. When I ask
a specific question, I want a specific answer not someone's idea of how it
should work.

The attitude came from you statement that a single form is a much better
way. Not true. It is the way you would do it.

Look at this way, a user has been storing data in a excel spreadsheet for a
long time. Now they want it on the central system.

You can give them a interface that requires them to click or double_click on
every row that needs updating, make the changes, and then click some other
button. The App then makes a trip back to the server each time, instead of a
batch transaction after all the editing is complete and a button is clicked,
or updating as it goes (when they press enter after editing a field, which
also requires a trip back to the server. This can work depending on the
network and server duty cycle)

The single form way: Two mouse clicks per update.
The grid way: One or zero mouse clicks per update.

They will never use the App. They will complain how slow and cumbersome it
is to use. It takes longer to use the app than it did with the spreadsheet.
This is a better way?

The single form design you mentioned has its place as well, but is not
always the better way.


Quote:
> Robert, did you get out of bed on the wrong side this morning or
> something?




Quote:


> > > I agree with Jason's approach as I don't like grid-based editing. But,
> > So you don't like Excel?

> I don't see what your point is.

> > > if you really want to do it with a DataGrid, you can do it by binding
> > > directly to an ADO recordset like this:

> > > 0. Dim a recordset in the form's General Declarations.
> > > 1. Open the recordset.
> > > 2. Set the grid's DataSource property to be the recordset.

> > > No Data Control required! There are three methods of handling the
> > > database updating:

> > > 0. Use a connected recordset so the updates occur when the user moves
> > > off the row they have altered or added. This can be confusing to the
> > > user as it's not very clear whether their updates have really
> > > happened. Also there's no way to offer a Cancel button because their
> > > changes have already been posted.

> > > 1. Use a disconnected recordset and then reconnect it and call its
> > > UpdateBatch method to get all the changes posted. I have a {*filter*}
> > > feeling that ADO will update all the rows it can but, if some of them
> > > won't go because of things like index or foreign key constraints, you
> > > end up with some changes saved and others not. Then you have to go
> > > through the recordset and use the Status property to identify the
> > > offending rows and tell the user what the problem was. Also the users
> > > need the relevant permissions on the underlying tables, which is fine
> > > for Access but the technique does not scale to SQL Server. (At least,
> > > it will work but it will not make you popular with the DBAs.)

> > This is totally unworkable on any platform with more than
> > one user. If you even mention recordset updates in our shop, you will be
> > banned from coding.

> I was not exactly recommending it. Just going through the options. I
> agree that the multi-user aspect is also another reason not to do it
> this way.

> > > 2. Use a disconnected recordset and manually go through the rows. If
> > > the Status property indicates the row has been added, edited or
> > > deleted in the recordset execute the relevant code to update the
> > > database accordingly. This a lot of work.

> > > As you can see, it's quite a job to implement scalable and robust grid
> > > editing. Much better to show a read-only grid and use a modal dialogue
> > > to edit one record at a time.

> > Maybe this should read: this is much better because it is my idea or,
this
> > much better because this is what I understand.

> What's with the attitude? The original poster wanted to know about
> editing in grids. I went through the other options as I see them and
> pointed out why each one is not too good. Then I recommended a
> technique that is widely regarded as a better way of doing it. It's
> not my own idea and I think I've demonstrated a reasonable grasp of
> other ways of doing it. What's your problem?




> > > > > Hi

> > > > > I am struggling with databases again in VB6. If I use the msflex
grid
> > > > > control I can display data from an Access 97 db, but can't update
it.
> > > > > If I use a data grid control I don't seem to be able to open the
data
> > > > > up into it, without using a data control (adodc). I don't want to
use
> > > > > the adodc.

> > > > > Preferably I would want to use the flex grid, does any one know of
a
> > > > > way of being able to update cells in this grid.

> > > > > Jules

> > > > Julia,

> > > > Why not double-click (or select a row, then click Edit) the row and
load
> >  a
> > > > form which display all the items in a way which you can edit (ie
using
> > > > textboxes, etc.)?

> > > > I usually put the primary key in the first column and make it zero
> >  width.

> > > > Double click on the row, identify the row, get the primary key, pass
it
> >  to
> > > > your edit form which loads the data to be edited (if primary key is
zero
> > > > we're adding a new record). Save the changes to the database, update
the
> > > > grid and close the edit form.

> > > > HTH



Sun, 02 Oct 2005 19:24:25 GMT  
 data grids/ms flex grids

Quote:

> My point is:
> It seems everyone is trying to get her to redesign her app. She asked
> a specific question about a specific problem, and I gave her a
> specific answer. Then everyone tries to get her to redesign her app.

<snip>

I think you're imagining things.

Julia said: "...I would want to use the flex grid, does any one know of a
way of being able to update cells in this grid."

You explained how to do that by placing a textbox over the cell to be
edited.

I outlined how to do it by using a separate form (or suggesting she purchase
a better grid).

There are pros and cons for both methods. I think that's all that needs to
be said.



Mon, 03 Oct 2005 22:12:36 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Grid (like MS Flex Grid) With a multi line select

2. flex grid or data grid or neither?

3. Populating MS Flex Grid w/Data

4. Modifying data in MS Flex Grid

5. Flex Grid/Selection Grid?

6. Flex Grid / Slection Grid

7. MS Hierarchical Flex Grid

8. About MS Flex Grid - Tell me

9. MS Flex Grid Headers

10. Printing form containing MS Flex Grid

11. MS Flex Grid Easy Question (I Hope)

12. VB6 MS Flex Grid Copying to clipboard

 

 
Powered by phpBB® Forum Software