|
-
Jul 2nd, 2002, 04:13 AM
#1
Thread Starter
Frenzied Member
MSHFlex Grid
Does anyone have sample code for using the MSHFlex Grid? That, for adding/editing/saving and deleting data in it. I am connecting to MS Access via adodc.
-
Jul 2nd, 2002, 04:24 AM
#2
AFAIK i have poster several times for flexgrid.......
it is better to search
i asure u u will find a lot...
-
Jul 2nd, 2002, 05:01 AM
#3
Thread Starter
Frenzied Member
I have looked but can't find what I need. I know how to save an edited grid to a database.
Code:
Private Sub cmdSave_Click()
RS.MoveFirst
For R = 1 To MSHFlexGrid1.Rows - 1
RS.Fields("Name") = MSHFlexGrid1.TextMatrix(R, 0)
RS.Fields("Address") = MSHFlexGrid1.TextMatrix(R, 1)
'etc ....
RS.MoveNext
Next
End Sub
To add new data to the database
Code:
Private Sub cmdSave_Click()
For R = 1 To MSHFlexGrid1.Rows - 1
With RS
.AddNew
.Fields("Name") = MSHFlexGrid1.TextMatrix(R, 0)
.Fields("Address") = MSHFlexGrid1.TextMatrix(R, 1)
'etc ....
.Update
End With
Next
End Sub
But when I try to amalgamate both, i.e. to allow the user to both add new data, edit existing data I run into problems.
Does anyone have better coding for this?
-
Jul 2nd, 2002, 05:05 AM
#4
How are you distinguishing between saving and adding new?
How are you adding data to the flexgrid?
I'm using a borderless textbox, and in the textbox lostfocus event, I update the database.
How do you want to do it?
-
Jul 2nd, 2002, 05:19 AM
#5
VB Code:
Option Explicit
Private Sub Form_Load()
Text1.Visible = False
End Sub
Private Sub MSF_EnterCell()
With Text1
.Left = msf.CellLeft
.Top = msf.CellTop
.Height = msf.CellHeight
.Width = msf.CellWidth
.Text = msf.Text
.Visible = True
.SetFocus
End With
End Sub
Private Sub msf_LeaveCell()
msf.Text = Text1
Text1.Visible = False
End Sub
grid
-
Jul 2nd, 2002, 05:36 AM
#6
Thread Starter
Frenzied Member
I am using borderless text boxs to edit my grid. And have similar code. The problem arises when I add/Edit data in the grid. How do you go about doning this? To you have two separate events for i) adding new data and saving AND ii) editing existing data and saving? And how do you handle the situation when the user edit existing data but also adds new lines to the grid?
-
Jul 2nd, 2002, 05:40 AM
#7
Originally posted by mel_flynn
How do you go about doning this? To you have two separate events for
i) adding new data and saving AND
ii) editing existing data and saving? And how do you handle the situation when the user edit existing data but also adds new lines to the grid?
In your flexgrid, you'll obviously have a primary key column (ok, assume). So, whenever you're to fire the event, check the cell for the existence of any content in the cell, and based upon that, set a boolean variable. Based upon the boolean var being true or false you can either addnew or update. (I use the objconn.execute method). This should cover both editing existing data and adding new data.
-
Jul 2nd, 2002, 05:41 AM
#8
insert or update code will be the same to flexgrid
only when u write data to database
loop to no of rows in grid
open the recordset with the unique key ..
if found then old record
update the values
if not found new record
use addnew method
-
Jul 2nd, 2002, 06:20 AM
#9
Thread Starter
Frenzied Member
No element in my grid is unique. The grid is acting as a details section
VB Code:
With adoQuoteDets
.ConnectionString = dataBase
.RecordSource = "Select * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
.CursorLocation = adUseClient
End With
Set grd.DataSource = adoQuoteDets
So there could be a series of lines for the one quote number.
Has anyone a sample application that they use MSHFlex Grid, incl. Adding, editing, deleting data in the grid? Any samples I have either only allowa the user to edit existing data or to only add new data.
-
Jul 2nd, 2002, 06:24 AM
#10
then what i can suggest
use transaction
delete the rows and make new entry into it...
hope u dont have any child to u table
-
Jul 2nd, 2002, 06:27 AM
#11
Thread Starter
Frenzied Member
delete the rows and make new entry into it...
This is what I was thinking of doing, but how do I only delete the data in the recordser without removing the contents of the grid?
-
Jul 2nd, 2002, 06:32 AM
#12
Originally posted by mel_flynn
This is what I was thinking of doing, but how do I only delete the data in the recordser without removing the contents of the grid?
do u keep track of the record status in the flexgrid...
AFAIK the best thing what u can do is
delete the rows from the tabel...
Code:
QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
and loop around and make insert
nothign to do with u grid contents clearing if u clear the grid u will lose what u have.... nothing to insert in database
-
Jul 2nd, 2002, 09:33 AM
#13
Thread Starter
Frenzied Member
delete the rows from the table...
QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
How do I delete rows from a table using the SQL statement?
-
Jul 2nd, 2002, 10:14 AM
#14
Thread Starter
Frenzied Member
How do I delete specific data from a table using the SQL statement?
i.e. Delete * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
-
Jul 2nd, 2002, 10:08 PM
#15
Originally posted by mel_flynn
How do I delete specific data from a table using the SQL statement?
i.e. Delete * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
u r question has the answer... the query which u pasted does that...
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
|