看vb方面的书,书中有现成的例子,书城有。
写入msflexgrid要用到text控件。
我手头现在没有现成的例子,sorry。
写入msflexgrid要用到text控件。
我手头现在没有现成的例子,sorry。
解决方案 »
- ??? browser.Document.tables(0).trs(0).tds(0).Value
- Global与public的区别
- 看看这几句代码
- 应聘的时候被人家要求背API,真是郁闷
- 如果工资管理系统的数据库文件名是 sz..db, 那么把数据库怎么样转换为excel文件?
- 不使用控件,如何直接在窗体上显示文字?print 不行啊
- 《visual studio 2005技术大全》、《SQL Server 2008基础教程》、《C#与VB.NET网络通信开发实战》三本全新书籍特价转让
- vb中的制作图表???
- 简单,简单--你想过吗?关于combo控件
- VB中使用SQL问题
- 谁能邦帮不弟,哪有关于文件 操作的实例,急\1!!!!!
- 语法错误
基本思想是:使用网格控件KeyPress事件,从键盘上接收所击键位的KeyAscii值,再由Chr$()或Chr()函数转换成字符,然后读出网格单元的当前Text值与由键盘接收到的字符相加,组成新的字符串,再赋给该单元的Text属性,即Grid.Text=Grid.Text+Chr$(KeyAscii)。程序清单如下: 程序中定义了两个Form级变量WgridCol%和WgridRow%。Sub Grid-KeyPress(KeyAscii as Integer)Grid.Col=WgridCol%Grid.Row=WgridRow%if KeyAscii=8Then `keyascii=8为退格删除键if Grid.Text<>””Then Grid.text=Mid$(Grid.text,1,Len(Grid.text)-1)‘删除最后一个字符ElseGrid.text=Grid.text+Chr$(KeyAscii)End ifEnd SubSub Grid-RowColChange()Wgrid.Col%=Grid.ColWgrid.Row%=Grid.RowEnd Sub 这样就可以实现对网格的任意输入,可以输入字符、数字等等。由于数字0到9的Ascii值为48到57,小数点Ascii的值为46,所以可以输入任意实数。若您想防止用户输入除数字、小数点以外的任何其他字符,可对来自于键盘的Ascii值进行判断,有条件地接收,就实现了仅输入数值字符。同理也可以限制只输入字母字符。 根据这种思想,也可以对VB中一切不具有输入功能,但具有KeyAscii或者KeyDown事件的控件进行直接输入,如标签Label等。
改编自 MS KB Q140888概述
MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能。在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。 实现步骤
1 打开 VB5, 开启一个新的工程。2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..”3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, BorderStyle 为 None(0)。4 在Form1 的代码中增加声明:Const ASC_ENTER = 13 '回车
Dim gRow As Integer
Dim gCol As Integer5 增加代码到 Grid_KeyPress 过程:Private Sub Grid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = Grid1.CellTop + Grid1.Top
Text1.Left = Grid1.CellLeft + Grid1.Left
' 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.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = Grid1.Text
' Show the text box:
Text1.Visible = True
Text1.ZOrder 0 ' 把 Text1 放到最前面!
Text1.SetFocus
' Redirect this KeyPress event to the text box:
If KeyAscii <> ASC_ENTER Then
SendKeys Chr$(KeyAscii)
End If
End Sub6 增加代码到 Text1_KeyPress 过程: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 Sub7 增加代码到 Text1_LostFocus 过程: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 Sub8 好了。 按 F5 开始测试。 您可以自由地在 Grid 中移动, 按回车可以开始或结束编辑。
msflexgrid.TextMatrix(i,j)=data
i,j分别代表表格的行和列
同时如果你是一条一条往表格中写数据的话你要线设置好表格的最大行数,否则汇报错
请看我的软件源码,里面有许多关于MsFlexGrid的操作,包括写记录。