Solved

DBGrid/MSFlex grid

Posted on 1998-11-09
7
372 Views
Last Modified: 2013-12-25
I'm trying to create a bound grid with 2 columns one a date and the other a bunch of text. With DBGrid I cannot word wrap the text, with MSFlexgrid I cannot edit the data and with both I cannot use an edit mask for the date. Does anyone know of a solution to these problems, preferably without buying a third-party control? TIA, Ed.
0
Comment
Question by:schoon
7 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Doesn't the DBGrid have a wraptext in the property sheet. of the control?
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 500 total points
Comment Utility
This line is in the documentation of dbgrid

If a cell's text is too long to be displayed in the cell, the text wraps to the next line within the same cell. To display the wrapped text, you must increase the cell's Column object's Width property and/or the DBGrid control's RowHeight property. At design time, you can change the column width interactively by resizing the column or by changing the column's width in the Column object's property page.

In the properties, choose layout and select wraptext
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Make sure that your RowHeight is large enough. The DBgrid does not automaticly increase the rowheight.

The wraptext is a property of the column object.

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:schild
Comment Utility
Hello schoon

The following article is MSDN’s article which deal with grid editing issue. Please try it and if you have more questions I will answer you.
In any case, instead of simple TextBox you can put a MuskEdit, which will help you both edit and wrap any cell and cell’s text.

**************************************************************
How to Edit Grid Cells in VB Using Overlapped Text Box


SUMMARY
The Grid custom control does not provide any text editing capability. The example program below shows how you can use a text box to perform text editing in the current cell of a grid.



MORE INFORMATION
The example program shown below enables you to edit the contents of a grid cell. When you press a key, the grid moves a text box to the position of the current cell and sets the focus to the text box. When you press the ENTER key or change focus away from the current cell, the program transfers the text in the text box back to the grid.



Steps to Create Example Program

Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

From the Tools menu, choose Custom Controls. Then check the Microsoft Grid Control check box. Click OK.

Place a grid (Grid1) and a text box (Text1) on Form1. Set the Grid1 Cols and Rows properties both to 4. Then size the grid to show all the cells. Set the Text1 BorderStyle property to None (0) and the Visible property to False (0).

Enter the following declarations in the general Declarations section:

   Const ASC_ENTER = 13        ' ASCII code of ENTER key.
   Dim gRow As Integer
   Dim gCol As Integer


Enter the following code in the Grid1_KeyPress procedure:

   Private Sub Grid1_KeyPress (KeyAscii As Integer)
      ' Move the text box to the current grid cell:
      Call grid_text_move(Grid1, Text1)

      ' Save the position of the grids Row and Col for later:
      gRow = Grid1.Row
      gCol = Grid1.Col

      ' Make text box same size as current grid cell:
      Text1.Width = Grid1.ColWidth(Grid1.Col) - 2 * Screen.TwipsPerPixelX
      Text1.Height = Grid1.RowHeight(Grid1.Row) - 2 * Screen.TwipsPerPixelY

      ' Transfer the grid cell text:
      Text1.Text = Grid1.Text

      ' Show the text box:
      Text1.Visible = True
      Text1.ZOrder 0
      Text1.SetFocus

      ' Redirect this KeyPress event to the text box:
      If KeyAscii <> ASC_ENTER Then
         SendKeys Chr$(KeyAscii)
      End If
   End Sub


Add the following code to the Text1_KeyPress procedure:

   Private Sub Text1_KeyPress (KeyAscii As Integer)
      If KeyAscii = ASC_ENTER Then
         Grid1.SetFocus  ' Set focus back to grid, see Text_LostFocus.
         KeyAscii = 0    ' Ignore this KeyPress.
      End If
   End Sub


Add the following code to the Text1_LostFocus procedure:

   Private Sub Text1_LostFocus ()
      Dim tmpRow As Integer
      Dim tmpCol As Integer

      ' Save current settings of Grid Row and col. This is needed only if
      ' the focus is set somewhere else in the Grid.
      tmpRow = Grid1.Row
      tmpCol = Grid1.Col

      ' Set Row and Col back to what they were before Text1_LostFocus:
      Grid1.Row = gRow
      Grid1.Col = gCol

      Grid1.Text = Text1.Text  ' Transfer text back to grid.
      Text1.SelStart = 0       ' Return caret to beginning.
      Text1.Visible = False    ' Disable text box.

      ' Return row and Col contents:
      Grid1.Row = tmpRow
      Grid1.Col = tmpCol
   End Sub


In the general Declarations section or in a separate .BAS file, add the following Sub routine:
Public Sub grid_text_move (Grid As Control, TextBox As Control)



      ' Move a text box to the position of the current cell in a grid:
      Dim X As Single   ' x position of current grid cell.
      Dim Y As Single   ' y position of current grid cell.
      Dim i As Integer  ' Column/row index.

      ' Skip grid border:
      X = Grid.Left
      Y = Grid.Top
      If Grid.BorderStyle = 1 Then
         X = X + Screen.TwipsPerPixelX
         Y = Y + Screen.TwipsPerPixelY
      End If

      ' Skip fixed columns and rows:
      For i = 0 To Grid.FixedCols - 1
         X = X + Grid.ColWidth(i)
         If Grid.GridLines Then
            X = X + Screen.TwipsPerPixelX
         End If
      Next
      For i = 0 To Grid.FixedRows - 1
         Y = Y + Grid.RowHeight(i)
         If Grid.GridLines Then
            Y = Y + Screen.TwipsPerPixelY
         End If
      Next

      ' Find current data cell:
      For i = Grid.LeftCol To Grid.Col - 1
          X = X + Grid.ColWidth(i)
          If Grid.GridLines Then
              X = X + Screen.TwipsPerPixelX
          End If
      Next
      For i = Grid.TopRow To Grid.Row - 1
          Y = Y + Grid.RowHeight(i)
          If Grid.GridLines Then
              Y = Y + Screen.TwipsPerPixelY
          End If
      Next

      ' Move the Text Box, and make small adjustments:
      TextBox.Move X + Screen.TwipsPerPixelX, Y + Screen.TwipsPerPixelY
   End Sub


Press the F5 key to run the program. Press a key to begin entering text into a cell. Type in some text. Press the ENTER key to finish editing the cell. Use the arrow keys to move to another cell. You can press the ENTER key to begin editing a cell without changing the contents of the cell.

**************************************************************

Good Luck
Schild
0
 

Expert Comment

by:BHimmerick
Comment Utility
You may want to just add another form and pass those values to it . . edit them . . then update the flex grid.   I hope this gives you more ideas.

Private Sub grdFlexGrid_DblClick()

    Dim lRowSel As Long
   
    frmUpdateGrid.Caption = "Update Grid"
    lRowSel = grdFlexGrid.RowSel
    frmUpdateGrid.txtField1 = grdFlexGrid.TextMatrix(lRowSel, 2)
    frmUpdateGrid.cboField2 = grdFlexGrid.TextMatrix(lRowSel, 3)
    frmUpdateGrid.cboField3 = grdFlexGrid.TextMatrix(lRowSel, 4)
   
    frmUpdateGrid.Show vbModal

End Sub

0
 

Author Comment

by:schoon
Comment Utility
Thankyou. I am trying to split the points between you and schild since you both  answered part of it.
0
 

Author Comment

by:schoon
Comment Utility
Schild and BHimmerick thankyou for your answers. I tried to split the points between you and Mirkwood but I couldn't.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now