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.
Printable View
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.
AFAIK i have poster several times for flexgrid.......
it is better to search
i asure u u will find a lot...;) :D
I have looked but can't find what I need. I know how to save an edited grid to a database.To add new data to the databaseCode: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
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.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
Does anyone have better coding for this?
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?
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
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?
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.Quote:
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?
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
No element in my grid is unique. The grid is acting as a details sectionSo there could be a series of lines for the one quote number.VB Code:
With adoQuoteDets .ConnectionString = dataBase .RecordSource = "Select * From QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text .CursorLocation = adUseClient End With Set grd.DataSource = adoQuoteDets
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.
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
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?Quote:
delete the rows and make new entry into it...
do u keep track of the record status in the flexgrid...Quote:
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?
AFAIK the best thing what u can do is
delete the rows from the tabel...
and loop around and make insertCode:QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
nothign to do with u grid contents clearing if u clear the grid u will lose what u have.... nothing to insert in database
How do I delete rows from a table using the SQL statement?Quote:
delete the rows from the table...
QuoteDets WHERE QuoteNo = " & cboQuoteNo.Text
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...;) :pQuote:
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