Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2003, 03:10 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 5
How to allow user to edit row in MSFLEXGRID?

Hi all, I have a MSFLEXGRID which populate data from db. However, I would like to allow the user to click on the row, it will allow user to edit the data or delete the row on the spot. Meaning if a row is selected, and if user press the 'delete' button on the keyboard, it will delete the whole row. If user change the data of the row, it will then update the data when it lost focus. I am not sure which command will allow me to do that. Please kindly let me know. Thank you.

BTW, when I click on the row, it will highlighted, but not the first column of the row ... how come? I use:

MSFlexGrid1.SelectionMode = flexSelectionByRow

Anyway, my code below:-

===============================

Dim statement As String
Dim c As Integer
Dim r As Integer
Dim col_wid() As Single
Dim field_wid As Single

Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset

Set conn = New ADODB.Connection

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=" & App.Path & "\account_db.mdb"

statement = "SELECT * FROM AUTO_SETTING ORDER BY CATEGORY_NAME"
Set rs = conn.Execute(statement)


' Use one fixed row and no fixed columns.
MSFlexGrid1.Rows = 2
MSFlexGrid1.FixedRows = 1
MSFlexGrid1.FixedCols = 0

' Display column headers.
MSFlexGrid1.Rows = 1
MSFlexGrid1.Cols = rs.Fields.count

ReDim col_wid(0 To rs.Fields.count - 1)


For c = 0 To rs.Fields.count - 1
MSFlexGrid1.TextMatrix(0, c) = rs.Fields(c).Name
col_wid(c) = TextWidth(rs.Fields(c).Name)
Next c

' Display the values for each row.
r = 1

Do While Not rs.EOF

MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1

For c = 0 To rs.Fields.count - 1

MSFlexGrid1.TextMatrix(r, c) = _
rs.Fields(c).Value

If c = 2 Then
MSFlexGrid1.TextMatrix(r, 2) = Format(rs.Fields(2).Value, "currency")
End If

' See how big the value is.
field_wid = TextWidth(rs.Fields(c).Value)
If col_wid(c) < field_wid Then col_wid(c) = _
field_wid
Next c

rs.MoveNext
r = r + 1

Loop


MSFlexGrid1.ScrollBars = flexScrollBarBoth
MSFlexGrid1.SelectionMode = flexSelectionByRow 'highlight selected row when user click

' Close the recordset and connection.
rs.Close
conn.Close

' Set the column widths.
For c = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.ColWidth(c) = col_wid(c) + 240
Next c

Reply With Quote
  #2  
Old October 18th, 2003, 02:38 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Maybe you can use of variation of this code.
The essential thing for you to do is have a msflex1_Click procedure.
Here I'm putting an "x" in the first column of the row that's clicked, and getting data from columns #6, #7 and #8.



Private Sub MSFlexGrid1_Click()
Dim xCol As Integer, xRow As Integer
Dim sumCost As Single, sumG As Single
Dim reachEst As Single, addReach As Single
Dim ratio As Single
Dim est As Single, oldReach As Single
Static kR As Integer, sumReach As Single
If UserForm1.TextBox1.Text = "" Then UserForm1.TextBox1.Text = 0
sumCost = CSng(UserForm1.TextBox1.Text)
sumG = CSng(UserForm1.TextBox3.Text)
xCol = MSFlexGrid1.col
xRow = MSFlexGrid1.Row
MSFlexGrid1.col = 0
If MSFlexGrid1.Text = "" Then
MSFlexGrid1.Text = "x"
MSFlexGrid1.col = 6
sumCost = sumCost + MSFlexGrid1.Text
kR = kR + 1
MSFlexGrid1.col = 7
sumG = sumG + MSFlexGrid1.Text
MSFlexGrid1.col = 8
addReach = MSFlexGrid1.Text

If kR = 1 Then
sumReach = addReach
oldReach = addReach
reachEst = addReach
End If
If kR > 1 Then
sumReach = sumReach + addReach
If UserForm1.TextBox2.Text = "" Or _
UserForm1.TextBox2.Text = "." Then UserForm1.TextBox2.Text = 0
Call RF
GoTo skip
End If
End If
If MSFlexGrid1.Text = "x" Then
MSFlexGrid1.Text = ""
MSFlexGrid1.col = 6
sumCost = sumCost - MSFlexGrid1.Text
MSFlexGrid1.col = 7
sumG = sumG - MSFlexGrid1.Text
TextBox2.BackColor = vbRed
Label5.Visible = True
reachEst = 0
GoTo skip
End If
skip:
If reachEst > 100 Then reachEst = 100
UserForm1.TextBox1.Text = Format(sumCost, "#,###,###")
UserForm1.TextBox2.Text = Format(reachEst, "###.#")
UserForm1.TextBox3.Text = Format(sumG, "#,###,###.#")
End Sub

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to allow user to edit row in MSFLEXGRID?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway