-
Sep 13th, 2005, 06:55 AM
#1
Thread Starter
Hyperactive Member
something color with MSFlexGrid
can someone post some examples of something cool you can do with MSFlexGrid. im not sure what i want yet, im still brainstorming. I want something like different colors rows(all that i came up with so far). hmm that's about it, so if you have something cool looking you can do with msflexgrid, please share with me. thanks in advance
-
Sep 13th, 2005, 08:17 AM
#2
Re: something color with MSFlexGrid
Don't if a cool or not but here's a quicky to do alt row colors:
VB Code:
Private Sub Command1_Click()
Dim i%, j%
With FGrid
DoEvents
If .Rows < 2 Then Exit Sub 'top row is a header
For j = 1 To .Rows - 1
For i = 1 To .Cols - 1
.Row = j
.Col = i
If j Mod 2 = 0 Then
.CellBackColor = &HDAF3CF 'light green
Else
.CellBackColor = vbWhite
End If
Next i
Next j
.Row = 2
.Col = 2
.SetFocus
End With
End Sub
-
Sep 13th, 2005, 08:19 AM
#3
Re: something color with MSFlexGrid
Navigation and Editing
VB Code:
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyReturn, vbKeyTab
'move to next cell.
With MSHFlexGrid1
If .Col + 1 <= .Cols - 1 Then
.Col = .Col + 1
Else
If .Row + 1 <= .Rows - 1 Then
.Row = .Row + 1
.Col = 0
Else
.Row = 1
.Col = 0
End If
End If
End With
Case vbKeyBack
With MSHFlexGrid1
'remove the last character, if any.
If Len(.Text) Then
.Text = Left(.Text, Len(.Text) - 1)
End If
End With
Case Is < 32
Case Else
With MSHFlexGrid1
.Text = .Text & Chr(KeyAscii)
End With
End Select
End Sub
-
Sep 13th, 2005, 08:51 AM
#4
Re: something color with MSFlexGrid
Highlighting row with alternative (other than default) color:
VB Code:
Option Explicit
Private Const ODDROW_COLOR = &HDAF3CF
Private Const EVENROW_COLOR = vbWhite
Private Const SELROW_COLOR = vbYellow
Private Sub FGrid_Click()
'==========================
Dim j%, iCurRow%
Static iLastRow As Integer
With FGrid
If .Row = 0 Then Exit Sub
iCurRow = .Row
If .Row <> iLastRow Then
.Row = iLastRow
For j = 1 To .Cols - 1
.Col = j
If iLastRow Mod 2 = 0 Then
.CellBackColor = ODDROW_COLOR
Else
.CellBackColor = EVENROW_COLOR
End If
Next j
Else
Exit Sub
End If
.Row = iCurRow
For j = 1 To .Cols - 1
.Col = j
.CellBackColor = SELROW_COLOR
Next j
iLastRow = .Row
End With
End Sub
-
Sep 13th, 2005, 09:07 AM
#5
Export FlexGrid To Excel
VB Code:
Dim i As Long
Dim p As Long
Dim newCell As String
Dim xl As Excel.Application
Set xl = CreateObject("excel.application")
xl.Workbooks.Open (App.Path & "\Book1")
DoEvents
xl.Visible = True
For i = 1 To MSFlexGrid1.Rows - 1
For p = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = p
MSFlexGrid1.Row = i
newCell = Chr(i + 64) & p
xl.Worksheets("Sheet1").Range(newCell).Value = MSFlexGrid1.Text
Next
Next
We are on a roll RhinoBull!
-
Sep 13th, 2005, 09:36 AM
#6
Re: something color with MSFlexGrid
Oh yea, we are!!!
Here is another one: getting selected values (this is really very quick sample):
VB Code:
Private Sub Command1_Click()
'================================
Dim i%, j%, intEndRow%, iEndCol%
Dim sBuffer$, arValues() As String
With FGrid
intEndRow = .RowSel
iEndCol = .ColSel
For i = intStartRow To intEndRow
sBuffer = sBuffer & .TextMatrix(i, iEndCol) & vbNewLine
Next i
End With
arValues = Split(sBuffer, vbNewLine)
For i = 0 To UBound(arValues)
Debug.Print arValues(i)
Next i
End Sub
-
Sep 13th, 2005, 09:38 AM
#7
Re: something color with MSFlexGrid
Export to a comma separated file:
VB Code:
Private Sub Command1_Click()
'============================
Dim i%, j%, strRowText$
Screen.MousePointer = vbHourglass
Open App.Path & "\test.csv" For Output As #1
With FGrid
For i = 1 To .Rows - 1
strRowText = ""
For j = 1 To .Cols - 1
strRowText = strRowText & .TextMatrix(i, j) & "," 'vbTab
Next j
Print #1, strRowText
Next i
End With
Close #1
Screen.MousePointer = vbDefault
End Sub
-
Sep 13th, 2005, 09:42 AM
#8
Re: something color with MSFlexGrid
Cut, Copy, Paste and Delete
VB Code:
Private Sub mnuEditCut()
'Cut the selection and put it on the Clipboard
EditCopy
EditDelete
End Sub
Private Sub mnuEditCopy()
'Copy the selection and put it on the Clipboard
Clipboard.Clear
Clipboard.SetText MSFlexGrid1.Clip
End Sub
Private Sub mnuEditPaste()
'Insert Clipboard contents
If Len(Clipboard.GetText) Then MSFlexGrid1.Clip = _
Clipboard.GetText
End Sub
Private Sub mnuEditDelete()
'Deletes the selection
Dim i As Integer
Dim j As Integer
Dim strClip As String
With MSFlexGrid1
For i = 1 To .RowSel
For j = 1 To .ColSel
strClip = strClip & "" & vbTab
Next
strClip = strClip & vbCr
Next
.Clip = strClip
End With
End Sub
Private Sub mnuEditSelectAll()
'Selects the whole Grid
With MSFlexGrid1
.Visible = False
.row = 1
.col = 1
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.TopRow = 1
.Visible = True
End With
End Sub
-
Sep 13th, 2005, 10:37 AM
#9
Re: something color with MSFlexGrid
Hmm ... between the two of us we have covered pretty much so that will give Whatupdoc a good start I'm sure.
-
Sep 13th, 2005, 06:22 PM
#10
Thread Starter
Hyperactive Member
Re: something color with MSFlexGrid
wow, thanks alot. that really helps
-
Sep 13th, 2005, 07:01 PM
#11
Lively Member
Re: something color with MSFlexGrid
wow so much info need to process it all. btw i rated this as execellent since theres so much good information!
I'm having a problem here. Do I put the serial number in the box that says 'serial number,' or do I put it in the box that says 'company'? - Oh, those poor tech support people
Jiveman: Lookie here, I can dig grease and butter on some draggin' fruit garden.
-
Sep 14th, 2005, 12:26 AM
#12
Re: something color with MSFlexGrid
There are a few things you can use to optimize your FlexGrid code.
1) Use the FillStyle property and work with a range of cells. Try to avoid looping through all rows and all columns. The code below colours alternate rows (similar to the code already posted) but executes much faster - especially with a large number of cells.
2) Use the Redraw property - set it to False before starting the code and back to True after the code executes. This ensures the grid is not refreshed until after the process has completed.
VB Code:
Dim i As Long
With Me.MSFlexGrid1
.Redraw = False
.FillStyle = flexFillRepeat
'change background colour of all cells (excluding fixed cells) to white
.Row = .FixedRows
.Col = .FixedCols
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.CellBackColor = vbWhite
'change background colour of all cells in each alternate row to light green
For i = .FixedRows + 1 To .Rows - 1 Step 2
.Row = i
.Col = .FixedCols
.ColSel = .Cols - 1
.CellBackColor = &HDAF3CF
Next
'set back to default
.FillStyle = flexFillSingle
'set current cell to top left
.Row = .FixedRows
.Col = .FixedCols
.Redraw = True
End With
3)A quick method to clear all cells in the grid.
VB Code:
With Me.MSFlexGrid1
.Redraw = False
.FillStyle = flexFillRepeat
'select a range of cells (in this case the entire grid).
.Row = .FixedRows
.Col = .FixedCols
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.Text = "" 'clears out data in all cells.
.FillStyle = flexFillSingle
.Row = .FixedRows
.Col = .FixedCols
.Redraw = True
End With
4) Some properties have the Row # or Column # as an argument. For example RowHeight, ColWidth, ColAlignment. If every row or every column will be set to the same value use -1 for the argument. Again, no need for looping.
MSFlexGrid1.RowHeight(-1) = 400
MSFlexGrid1.ColAlignment(-1) = flexAlignRightCenter
-
Sep 30th, 2005, 09:17 PM
#13
Member
Re: Export FlexGrid To Excel
Hi Hack,
I find this one interesting. Can you please help a vb6 newbie here on how to include the column headings into the excel file?
A bunch of thanks to ya'll.
Originally Posted by Hack
VB Code:
Dim i As Long
Dim p As Long
Dim newCell As String
Dim xl As Excel.Application
Set xl = CreateObject("excel.application")
xl.Workbooks.Open (App.Path & "\Book1")
DoEvents
xl.Visible = True
For i = 1 To MSFlexGrid1.Rows - 1
For p = 1 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = p
MSFlexGrid1.Row = i
newCell = Chr(i + 64) & p
xl.Worksheets("Sheet1").Range(newCell).Value = MSFlexGrid1.Text
Next
Next
We are on a roll RhinoBull!
-
Nov 9th, 2005, 09:28 AM
#14
Re: something color with MSFlexGrid
New procedure added that populates flexgrid from comma delimited file:
VB Code:
Private Sub Command1_Click()
'=====================================================
Dim i%, j%, strHeader$, strLine$, arItems() As String
Screen.MousePointer = vbHourglass
Open App.Path & "\test.csv" For Input As #1
With FGrid
.Clear
.Rows = 1
'set headers
Line Input #1, strHeader
arItems = Split(strHeader, ",")
.Cols = UBound(arItems) + 1
For j = 0 To UBound(arItems)
.TextMatrix(i, j) = arItems(j)
Next j
'poop through file and populate rest of a grid
i = 1
Do While Not EOF(1)
'read line
Line Input #1, strLine
If Not strLine = strHeader Then
'split values on comma
arItems = Split(strLine, ",")
'---
.AddItem ""
For j = 0 To UBound(arItems)
.TextMatrix(i, j) = arItems(j)
Next j
'---
i = i + 1
End If
Loop
End With
Close #1
Screen.MousePointer = vbDefault
End Sub
-
Mar 30th, 2006, 06:18 AM
#15
Member
Re: something color with MSFlexGrid
i've just used the export to excel code (works great) and i've modified it to include the column and row headings
VB Code:
Dim q As Long
Dim p As Long
Dim newCell As String
Dim xl As Excel.Application
Set xl = CreateObject("excel.application")
xl.Workbooks.Open ("D:\University\3rd Year\Final Year Project\My Results\Book1")
DoEvents
xl.Visible = True
For p = 0 To MSFlexGrid1.Rows - 1
For q = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = q
MSFlexGrid1.Row = p
newCell = Chr(q + 65) & p + 1
xl.Worksheets("Sheet1").Range(newCell).Value = MSFlexGrid1.Text
Next
Next
-
Jul 3rd, 2006, 09:54 AM
#16
Re: something color with MSFlexGrid
Allows the user to rearrange the columns using Drag/Drop.
VB Code:
Private mlngDragColumn As Long
Private Sub Form_Load()
With Me.MSFlexGrid1
.Cols = 5
.TextMatrix(0, 1) = "Column 1"
.TextMatrix(0, 2) = "Column 2"
.TextMatrix(0, 3) = "Column 3"
.TextMatrix(0, 4) = "Column 4"
.DragMode = vbManual
.DragIcon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Dragdrop\DROP1PG.ICO")
mlngDragColumn = -1
End With
End Sub
Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
If Source Is MSFlexGrid1 Then
If Source.MouseCol >= Source.FixedCols Then
If mlngDragColumn <> -1 Then
Source.ColPosition(Source.MouseCol) = mlngDragColumn
End If
End If
End If
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
With MSFlexGrid1
If .MouseRow < .FixedRows And .MouseCol >= .FixedCols Then
mlngDragColumn = .MouseCol
.Drag vbBeginDrag
End If
End With
End If
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
mlngDragColumn = -1
End Sub
-
Jul 10th, 2006, 02:54 AM
#17
Lively Member
Re: something color with MSFlexGrid
how about inserting the selected row in the msflexgrid into textbox/labelbox?
-
Jul 10th, 2006, 07:47 AM
#18
Re: something color with MSFlexGrid
What about it? Just use TextMatrix property.
-
Jul 10th, 2006, 08:15 AM
#19
Lively Member
Re: something color with MSFlexGrid
oh my goodness! i totally forgot bout that textmatrix property. lol sorry.
edit: btw, how do i automatically refresh the flexgrid after deleting one of the records in it?
use .refresh? it doesnt work.
Edit Again: Sorry. found it.. it was the removeitem from rowsel.
Last edited by Kaine; Jul 10th, 2006 at 09:09 PM.
-
Nov 8th, 2006, 11:26 AM
#20
Junior Member
Re: something color with MSFlexGrid
Hi all,
Found all this info overwhelming. I have been looking for this for the last 6 months.
I have however found one anoying thing with the Drag and Drop, so have changed it a bit.
Before It would set the column droped on to the position you dragged from, this meaning that the column being dragged only moved 1 place up or down.
But by swapping 2 of the parameters it works as intended.
Here is the altered code: -
VB Code:
Private mlngDragColumn As Long
Private Sub Form_Load()
With Me.MSFlexGrid1
.Cols = 5
.TextMatrix(0, 1) = "Column 1"
.TextMatrix(0, 2) = "Column 2"
.TextMatrix(0, 3) = "Column 3"
.TextMatrix(0, 4) = "Column 4"
.DragMode = vbManual
.DragIcon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Dragdrop\DROP1PG.ICO")
mlngDragColumn = -1
End With
End Sub
Private Sub MSFlexGrid1_DragDrop(Source As Control, x As Single, y As Single)
If Source Is MSFlexGrid1 Then
If Source.MouseCol >= Source.FixedCols Then
If mlngDragColumn <> -1 Then
Source.ColPosition(mlngDragColumn) = Source.MouseCol ' <-- the difference is here
End If
End If
End If
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
With MSFlexGrid1
If .MouseRow < .FixedRows And .MouseCol >= .FixedCols Then
mlngDragColumn = .MouseCol
.Drag vbBeginDrag
End If
End With
End If
End Sub
Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
mlngDragColumn = -1
End Sub
Hope this might help someone else.
-
Dec 29th, 2006, 01:53 AM
#21
Re: something color with MSFlexGrid
Fast Populate Flexgrid from Database
VB Code:
Private Sub Command1_Click()
Screen.MousePointer = vbHourglass
Set rs = New ADODB.Recordset
strsearch = "SELECT * FROM TblName ORDER BY AnyField"
rs.Open strsearch, adoc, adOpenDynamic, adLockOptimistic
rs.Requery
If rs.RecordCount = 0 Then
MSFlexGrid1.Clear
MsgBox "No record found"
Screen.MousePointer = vbNormal
Exit Sub
ElseIf rs.RecordCount >= 1 Then
'populate flexgrid box
With MSFlexGrid1
.Clear
.Rows = rs.RecordCount + 1
.Cols = rs.Fields.Count - 1
.Row = 1
.Col = 0
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.Clip = UCase(rs.GetString(adClipString, -1, Chr(9), Chr(13), vbNullString))
.Row = 1
End With
End If
Screen.MousePointer = vbNormal
End Sub
The GetString method returns the specified Recordset as a string so there's no loop needed.
-
Jan 5th, 2007, 11:12 PM
#22
Re: something color with MSFlexGrid
Someone has recently asked about autosizing columns so I found this very old thread:
Autosizing Columns in MSFlexGrid
-
Feb 8th, 2007, 04:16 AM
#23
Junior Member
Re: something color with MSFlexGrid
Originally Posted by zynder
Fast Populate Flexgrid from Database
VB Code:
Private Sub Command1_Click()
Screen.MousePointer = vbHourglass
Set rs = New ADODB.Recordset
strsearch = "SELECT * FROM TblName ORDER BY AnyField"
rs.Open strsearch, adoc, adOpenDynamic, adLockOptimistic
rs.Requery
If rs.RecordCount = 0 Then
MSFlexGrid1.Clear
MsgBox "No record found"
Screen.MousePointer = vbNormal
Exit Sub
ElseIf rs.RecordCount >= 1 Then
'populate flexgrid box
With MSFlexGrid1
.Clear
.Rows = rs.RecordCount + 1
.Cols = rs.Fields.Count - 1
.Row = 1
.Col = 0
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.Clip = UCase(rs.GetString(adClipString, -1, Chr(9), Chr(13), vbNullString))
.Row = 1
End With
End If
Screen.MousePointer = vbNormal
End Sub
The GetString method returns the specified Recordset as a string so there's no loop needed.
Hi Zander, only one problem with this is what if the recordset cant return a correct count, you see sometimes i get a recordset that has "-1" for the record count. So i use the following code: -
VB Code:
Public Function PopFlex(RSdb As ADODB.Recordset, Grid As MSFlexGrid, fixed As Integer) As Integer
Dim i As Integer, j As Integer, sizer() As Variant
Grid.FixedRows = 1
Grid.FixedCols = fixed
RSdb.MoveFirst
ReDim sizer(RSdb.Fields.Count)
For i = 0 To RSdb.Fields.Count - 1
sizer(i) = 0
Next
If Not RSdb.EOF Then
Grid.Rows = 1
Grid.cols = RSdb.Fields.Count
For i = 0 To RSdb.Fields.Count - 1
Grid.TextMatrix(0, i) = RSdb.Fields(i).Name
If sizer(i) < (GetTextWidth(RSdb.Fields(i).Name) + 100) Then
sizer(i) = (GetTextWidth(RSdb.Fields(i).Name) + 100)
End If
Next
Dim teststr As String, testarr As Variant, initval As String
initval = RSdb.GetString(adClipString, 1, Chr(9), ";", "")
Do While Not RSdb.EOF
For i = 0 To RSdb.Fields.Count - 1
If sizer(i)<(GetTextWidth(RSdb(RSdb.Fields(i).Name)) + 100) Then
sizer(i)=(GetTextWidth(RSdb(RSdb.Fields(i).Name)) + 100)
End If
Next
RSdb.MoveNext
Loop
testarr = split(initval,";")
For i = 0 to UBound(testarr)
Grid.AddItem testarr(i)
Next
For i = 0 to UBound(sizer)
Grid.ColWidth(i) = sizer(i)
Next
i = Grid.Rows
Grid.RemoveItem i
End If
PopFlex = Grid.Rows - 1
End Function
ok it is not brilliant but it always works.
also the function GetTextWidth is used to autosize the column widths.
VB Code:
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Public Function GetTextWidth(ByRef Frm as Form, ByVal Value As String) As Long
Dim hFont As Long
Dim hFontOrig As Long
Dim lWidth As Long
Dim hdc As Long
Dim sTemp As String
Dim sz As SIZE
hdc = GetDC(Frm.hWnd)
hFont = GetStockObject(ANSI_VAR_FONT)
hFontOrig = SelectObject(hdc, hFont&)
GetTextExtentPoint32 hdc, Value, Len(Value), sz
lWidth = sz.cx
SelectObject hdc, hFontOrig
DeleteObject (hFont)
ReleaseDC Frm.hWnd, hdc
GetTextWidth = lWidth * 15
End Function
This function can be used to resize any control correctly, so long as you take the padding into account for each control.
-
Feb 8th, 2007, 04:24 AM
#24
Junior Member
Re: something color with MSFlexGrid
Forgot to add this Constant to my last post for the GetTextWidth Function
Private Const ANSI_VAR_FONT As Long = 12
Also the "If NOT RSdb.EOF then"
Should actually be: -
If NOT (RSdb.EOF And RSdb.BOF) then
and if you want to trap an empty recordset and return a "No Info" message to the flexgrid, then you can put an "else" in that same if block.
-
Apr 17th, 2007, 12:02 PM
#25
Re: something color with MSFlexGrid
Originally Posted by Izzyonstage
Hi Zander, only one problem with this is what if the recordset cant return a correct count, you see sometimes i get a recordset that has "-1" for the record count.
Old thread, but rs.CursorLocation = adUseClient solves that.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Aug 25th, 2007, 06:45 PM
#26
Re: something color with MSFlexGrid
Here is another fast exporting to excel without looping through cells. It's a basic copy and paste. Good for exporting thousands of records.
Fast Export Flexgrid to Excel
Code:
Private Sub cmdExportToExcel_Click()
Dim xls As Excel.Application
Set xls = New Excel.Application
xls.Workbooks.Open (App.Path & "\Template.xls")
xls.Visible = True
'select all
With MSFlexGrid1
.Visible = False
.Row = 0 'will depend on the user
.Col = 1 'will depend on the user
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.TopRow = 1
.Visible = True
End With
Clipboard.Clear
'copy to clipboard
Clipboard.SetText MSFlexGrid1.Clip
'paste to excel
xls.ActiveSheet.Paste
Set xls = Nothing
End Sub
At first I was using Hack's code, but exporting thousands of records is a bit slow, I experimented if copy paste was possible and it was.
Last edited by zynder; Aug 25th, 2007 at 06:50 PM.
Reason: added Set xls = Nothing
-
Sep 27th, 2010, 08:33 AM
#27
Lively Member
Re: something color with MSFlexGrid
I want to add a combo box on mshflexgrid.
i want when the user press enter on combo box then the text in combo box
will be with mshflexgrid for i.e.
Code:
Mf1.Text = cmbval.text
Here mf1 is mshflexgrid and cmbval is combo box.
Then combo box (cmbval) will be hide and setfocus to mshflexgrid's next column.
I am waiting for your reply.
Thanks.
I belive in pray. I pray for you.
You may have happy, healthy, wealthy life.
-
Sep 27th, 2010, 08:46 AM
#28
Re: something color with MSFlexGrid
Originally Posted by Eliminator2009
I want to add a combo box on mshflexgrid.
You may as well open a new thread for that.
-
Jan 9th, 2011, 04:34 PM
#29
New Member
Re: something color with MSFlexGrid
Rhino.
Is there an easy way to insert and delete an entire row anywhere in a MSHFlexgrid???
Cheers
-
Jan 9th, 2011, 05:06 PM
#30
Re: something color with MSFlexGrid
Use AddItem/RemoveItem:
Code:
Private Sub Command1_Click()
MSFlexGrid1.AddItem "New row", 3 'or whatever rowindex you want
End Sub
Private Sub Command2_Click()
MSFlexGrid1.RemoveItem 3 'or whatever rowindex you want
End Sub
-
Jan 9th, 2011, 05:12 PM
#31
New Member
Re: something color with MSFlexGrid
You're kidding??
That easy..
How did i miss that? (prob by trying to overcomplicate things as i do..)
Thanks again.
..
..
Rhino
Bunged that in and works a treat.
I am in your debt yet again
Many thanks.
Last edited by Steamyrotter; Jan 9th, 2011 at 06:41 PM.
Reason: added a bit more..
-
May 18th, 2012, 09:45 PM
#32
New Member
Re: something color with MSFlexGrid
hello, Have you a example to import Xml file in flexgrid?
many thanks
-
Feb 11th, 2014, 03:18 AM
#33
New Member
Re: something color with MSFlexGrid
execellent work
can you add how to print the gird please?
-
Feb 11th, 2014, 03:54 AM
#34
Re: something color with MSFlexGrid
Have a look here and here
-
Feb 11th, 2014, 04:44 AM
#35
New Member
Re: something color with MSFlexGrid
Thank you very much
I'll check them now
Originally Posted by Arnoutdv
-
Aug 25th, 2014, 08:33 AM
#36
Registered User
Re: something color with MSFlexGrid - NEW!
hello,
just wan't to ask if not late..does anyone here have a code for msflexgrid(vb6) that hightlight the entire row just like ms access 2007 or 2012?..
i mean, if i select the cell a textbox will appear then the entire row will get highlighted while the text is in focus..
hopefully you understand what i mean..
-
Aug 25th, 2014, 09:15 AM
#37
Re: something color with MSFlexGrid
Here's an example....place an MSFlexgrid on the form. Make it 5 columns (0-4), and make the top row Fixed.
Code:
Option Explicit
Private Sub Form_Load()
grid.Row = 1
Dim x As Integer
For x = 0 To grid.Rows - 1
grid.TextMatrix(1, x) = Str(x)
Next x
End Sub
Private Sub grid_click()
Dim a As Integer, b As Integer, rowval As Integer, i As Integer
With grid
For a = 0 To .Rows - 1
.Row = a
For b = 0 To .Cols - 1
.Col = b
.CellBackColor = vbWhite 'RESETS ALL ROWS/COLS to white...if your background color is not white, simply put that color here instead of vbWhite
Next b
Next a
End With
With grid
'
' rowval = .MouseRow
.Row = .MouseRow ' the row you want to highlight
For i = 0 To .Cols - 1
.Col = i
.CellBackColor = vbYellow
Next i
End With
End Sub
Also, next time, instead of resurfacing an old thread, start a new one of your own....ok?
-
Sep 19th, 2014, 01:14 AM
#38
Addicted Member
Re: something color with MSFlexGrid
Code:
Dim vSql As String
Dim vRs As New Recordset
vSql = "SELECT Id,AdmNo, Name, Phone1 FROM Students ORDER BY ID"
Set vRs = New ADODB.Recordset
vRs.Open vSql, cnnRice, adOpenKeyset, adLockOptimistic
Grid1_clear
If Not vRs.EOF Then
With MSFGrid1
.rows = vRs.RecordCount + 1
.Row = 1
.Col = 1
.RowSel = .rows - 1
.ColSel = .cols - 1
.clip = UCase(vRs.GetString(adClipString, -1, Chr(9), Chr(13), vbNullString))
.Row = 1
End With
End If
This is with ref. to Post #21 (Zynder). This Fast Populates the Flexgrid from Database. Is it possible to give RowNumbers (starting from 1) in the first column simultaneously ?
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
|