|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > How to allow user to edit row in MSFLEXGRID? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|