Show multiple buttons in Data grid view - visual-foxpro

I needed to add two buttons inside a single column in data grid view in Visual Foxpro, , but only one active appears in the column.
the two buttons could be shown in each cell of that column.
Is it possible to show both buttons?

I needed to add two buttons inside a single column in data grid [...] Is it possible to show both buttons?
Yes, you can put a Container object into the Grid.Column and put two Buttons into the Container. Minimal, Reproducible Example:
LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN
DEFINE CLASS TestForm as Form
AutoCenter = .T.
PROCEDURE Load
LOCAL i
CREATE CURSOR temp (test Int)
FOR i = 1 TO 10
INSERT INTO temp VALUES (i)
ENDFOR
GO TOP
ENDPROC
ADD OBJECT Grid1 as Grid WITH ;
RecordSource = 'temp', ColumnCount = 1, RowHeight = 30
PROCEDURE Grid1.Init()
WITH This.Column1
.Width = 200
.AddObject('Container1','TestContainer')
.Container1.Visible = .T.
.CurrentControl = 'Container1'
.Sparse = .F.
ENDWITH
ENDPROC
ENDDEFINE
DEFINE CLASS TestContainer as Container
Width = 200
Height = 27
ADD OBJECT Button1 as CommandButton WITH ;
Height = 24, Caption = "Button1"
PROCEDURE Button1.Click
MESSAGEBOX(This.Caption)
ENDPROC
ADD OBJECT Button2 as CommandButton WITH ;
Height = 24, Left = 100, Caption = "Button2"
PROCEDURE Button2.Click
MESSAGEBOX(This.Caption)
ENDPROC
ENDDEFINE

Related

Control Shell.Explorer.2 with google maps issue in VFP

I have a form in VFP9 that shows a map in a control Shell.Explorer.2. In previous Google API the form works fine, but now the control doesn't show the page, and an Script Error appears:
The page is a simple marker from
https://developers.google.com/maps/documentation/javascript/examples/marker-simple?hl=es
Inside of the VFP form I have a TEXT ENDTEXT block, in order to create a temporal webpage(MyHtml.htm) that is shown in the control.
The error indicate the follows lines as error:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=MY-GOOGLE-API-KEY&callback=initMap">
</script>
If I display the page in IExplorer 11, Firefox, Chrome, Edge, works fine, but with the control Shell.Explorer.2 I get an error and the control doesn't show the map. If I remove the Script, the control doesn't show the map.
Is this type of script no longer supported in shell.explorer.2?
Any documentation or help?
Unfortunately you have provided only partial code to talk upon. This sample code, which was written as an answer to a question on Foxite works well and use Shell.Explorer:
Local lcCoordinates, lat, lon, lcUrl
lcCoordinates = [14 ° 53'38.5 "N, 24 ° 30'31.0" W]
Alines(laParts, m.lcCoordinates, 1+4, '°',"'",'"' ,' ')
lat = Str((Val(laParts[1]) + Val(laParts[2])/60 + Val(laParts[3])/3600) * Iif(laParts[4] = 'N',1,-1),9,6)
lon = Str((Val(laParts[5]) + Val(laParts[6])/60 + Val(laParts[7])/3600) * Iif(laParts[8] = 'E',1,-1),9,6)
lcUrl = Textmerge("https://www.google.com/maps/#<< m.lat >>,<< m.lon >>,11z")
ShowMap(m.lcUrl)
Procedure ShowMap(tcUrl)
Public oForm
oForm = Createobject('form1')
oForm.Show()
oForm.HTMLViewer.Navigate2(m.tcUrl)
Endproc
Function GetHTML
Local myVar
TEXT to myVar noshow
ENDTEXT
Return myVar
Endfunc
Define Class HTMLViewer As OleControl
OleClass = 'Shell.Explorer'
Procedure Refresh
Nodefault
Endproc
Procedure LoadHTML(tcHTML)
With This
.Navigate2("about:blank")
.Document.Write(m.tcHTML)
Endwith
Enddefine
Define Class form1 As Form
Height = 600
Width = 800
Caption = "HTML sample"
Add Object HTMLViewer As HTMLViewer With ;
Top = 10, ;
Left = 10, ;
Height = 580, ;
Width = 780, ;
Anchor = 15,;
Visible = .T., ;
Name = "HTMLViewer"
Procedure Init
Lparameters tcHTML
If !Empty(m.tcHTML)
With Thisform.HTMLViewer
.LoadHTML(m.tcHTML)
Endwith
Endif
Endproc
Procedure HTMLViewer.NavigateError
Lparameters pdisp, url, frame, statuscode, Cancel
Set Step On
Cancel = .T.
Endproc
Procedure HTMLViewer.BeforeNavigate2
Lparameters pdisp, url, Flags, targetframename, postdata, headers, Cancel
Cancel = .T. && prevents actual navigation
Endproc
Procedure HTMLViewer.Refresh
Nodefault
Endproc
Enddefine

Unable to allow row selection on click over mshflexgrid control in vb6

The form that has mshflexgrid control is not allowing to select the row on which the mouse click has done. Sometimes it allows selection of previous row and not the row which is been clicked
I have tried adding one to the property .RowSel of mshflexgrid to allow the row selection, it is not working for second row selection.
Private Sub MSHFlexGrid1_Click()
last_row_selected = MSHFlexGrid1.RowSel
If last_row_selected <> 1 Then last_row_selected = last_row_selected + 1
With MSHFlexGrid1
If (boolShift And vbShiftMask) = vbShiftMask Then
SelectionOneAfterTheOther
ElseIf (boolShift And vbCtrlMask) = vbCtrlMask Then
SelectUnSelectGridRow
Else
UnSelectAllGridRows
.Row = last_row_selected
.ColSel = .Cols - 1
.CellBackColor = vbHighlight
.CellForeColor = vbHighlightText
End If
End With
MSHFlexGrid1.Refresh
End Sub
It seems that the .RowSel property isn't taking correct value for selection of row
The result needs to be proper selection of row on which it is clicked.
In your grid Click event, try something like this:
With MSHFlexGrid1
If .Row = .RowSel Then
.Col = .Cols - 1
.ColSel = 0
End If
End With
You may need to set SelectionMode on the grid control also. The above code should work if set to flexSelectionFree
Have you set the SelectionMode property? If not, you get to it by clicking "Custom" in the properties window. This opens a dialog where SelectionMode is one of the available properties.

How to click on webtable specific row

I have this code that clicks on first row and column one just fine.
Set oExcptnDetail = Description.Create
oExcptnDetail("micclass").value = "WebElement"
oExcptnDetail("html tag").value = "TD"
Set chobj=Browser("").Page("").WebTable("Code").ChildObjects(oExcptnDetail)
chobj(0).Click
How can I click on a specific row using above code?
I used childitem that did not work.
set objLink = Browser("bb").Page("bb").WebTable("Name_2").ChildItem(4, 1, "WebElement",0)
Update 1
I tried the below code. It did not click row 3 col 1.
Set desc = Description.Create
desc("html tag").value = "TR"
Set rows = table.ChildObjects(desc)
desc("html tag").value = "TD"
Set cells = rows(3).ChildObjects(desc)
Set TableCell = cells(1)
Browser("").Page("").WebTable(TableCell).Click
UFT's ChildItem function returns elements contained within cells, this means that it won't return the TD that is the cell, only its descendants.
In order to get the cell itself you should use WebTable.Cell, this is a relatively new functionality in UFT and you may not have it. If you don't you should be able to write a helper function like this (note I'm writing this without checking it out, it may need additional work and error handling):
Function TableCell(table, nRow, nCol)
Set desc = Description.Create
desc("html tag").value = "TR" ' Or "T[RH]" to capture TH too
Set rows = table.ChildObjects(desc)
desc("html tag").value = "TD"
Set cells = rows(nRow).ChildObjects(desc)
Set TableCell = cells(nCol)
End Function
Then you can use RegisterUserFunc to use it as WebTable.Cell if you wish.
Then you can use it thus:
TableCell(Browser("").Page("").WebTable("Code"), 4, 1).Click
Or if you used RegisterUserFunc to register it as Cell:
Browser("").Page("").WebTable("Code").Cell(4, 1).Click

Event Handlers for Dynamic Table Layout Panel in Visual Basic

I am making a risk-type game for school that dynamically creates a 4x4 grid of buttons inside a table layout panel in visual basic. I have successfully created the panel and buttons with names that correspond to the row and column of the button. There are also two parallel arrays - one for button owner and the other for button number - that correspond to the owner of the button and the number of "armies" in the button. My issue is that when the user clicks a certain button, I need to reference the button name/value to know how many "armies" the button has to control the "attack" portion of the player's turn.
The following code creates the table layout panel and the buttons with names.
'Create table Dynamically
Dim ColCount As Integer = 4
Dim RowCount As Integer = 4
Dim f As New System.Drawing.Font("Arial", 15)
riskTable.AutoScroll = True
riskTable.Dock = DockStyle.Fill
riskTable.ColumnCount = ColCount
riskTable.RowCount = RowCount
For rowNo As Integer = 0 To riskTable.RowCount - 1
For columnNo As Integer = 0 To riskTable.ColumnCount - 1
Dim buttonname As String
buttonname = "B" & rowNo & columnNo
Dim button As Control = New Button
button.Size = New Size(179, 100)
button.Name = buttonname
button.Text = "1"
button.ForeColor = Color.White
button.Font = f
AddHandler button.Click, AddressOf buttonname_Click
riskTable.Controls.Add(button, columnNo, rowNo)
Next
Next
Me.Controls.Add(riskTable)
This is the dynamic event handler that I created. I tried using 'Me.Click' to get the name of the button, but it only returns the name of the form. I need to have code in here that references the name of the currently clicked button to then in turn reference the box owner and box number arrays.
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
MessageBox.Show(Me.Name)
End Sub
Any help would be greatly appreciated! I think that once I get this working, the rest of the game will be pretty simple to figure out.
Thanks!
Put the name in 'button.Tag' instead/also:
button.Tag = buttonname
Then it is easy to get the name with:
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
Dim result As String = CType(CType(sender, System.Windows.Forms.Button).Tag, String)
End Sub
(Check the System.Windows.Forms.Button though, might need some tweak to match your buttons inside the table. riskTable.Controls.button ?)

View Datagridview in Print Preview Window

I am creating an application in vb.net. I have a datagridview control in my VB form. I need to view it on printpreview window with the contents in it. I have other control like labels and textboxes in the form and I can view all in printpreview. In the case of Datagridview control, I have a working printpreview code which I got from net. My problem is, I need to change the x and y positions of datagridview control. With the following code, the datagridview control is displaying over the other controls. I dont know how to do it in this code. Please help me.
I need to change the x and y positions of DataGridView like given in the below code(50 and 225).
e.Graphics.DrawString(Label7.Text, Label7.Font, Brushes.Black, 50, 225)
The code I used to display gridview is given below.
Code :
Dim ColumnCount As Integer = DataGridView1.ColumnCount
Dim RowCount As Integer = DataGridView1.RowCount
Dim CellTopPos As Integer = PrintDocument1.PrinterSettings.DefaultPageSettings.Margins.Top
For Row = 0 To RowCount - 2
Dim CellLeftPos As Integer = PrintDocument1.PrinterSettings.DefaultPageSettings.Margins.Left
For Cell = 0 To ColumnCount - 1
Dim CellValue As String = DataGridView1.Rows(Row).Cells(Cell).Value.ToString()
Dim CellWidth = DataGridView1.Rows(Row).Cells(Cell).Size.Width + 10
Dim CellHeight = DataGridView1.Rows(Row).Cells(Cell).Size.Height
Dim Brush As New SolidBrush(Color.Black)
e.Graphics.DrawString(CellValue, New Font("arial", 9), Brush, CellLeftPos, CellTopPos)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)
CellLeftPos += CellWidth
Next
CellTopPos += DataGridView1.Rows(Row).Cells(0).Size.Height
Next
Use this class .. unfortunately there is characters limit so i can not able to post code
http://www.codeproject.com/Articles/18042/Another-DataGridView-Printer

Resources