VB MSFLEXGRID

来源:百度知道 编辑:UC知道 时间:2024/07/04 13:08:49
条件:三个textbox,一个msflexgrid , 一个Command 控件 列数固定

需求:在textbox里输入内容,点击一次command 后3个textbox里的内容输入

到msflexgrid里 同时textox清空.有新数据输入并点击command后,MSFlexGrid依次把新数据下一行而不覆盖上一行.

问题:我写的只是单纯的覆盖第一行,而没有依次的把新数据写入下一行.

我的代码:
Private Sub Command1_Click()

With MSFlexGrid1

.Rows = Rows + 1

.TextMatrix(Rows, 1) = Text1.Text

.TextMatrix(Rows, 2) = Text2.Text

.TextMatrix(Rows, 3) = Text3.Text

.AddItem (Rows)

End With

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""

End Sub

Private Sub Command1_Click()
With MSFlexGrid1
'Debug.Print .Rows
.TextMatrix(.Rows - 1, 1) = Text1.Text
.TextMatrix(.Rows - 1, 2) = Text2.Text
.TextMatrix(.Rows - 1, 3) = Text3.Text
.AddItem ("")
End With
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub

代码如下。
==============
Private Sub Form_Load()
MSFlexGrid1.Cols = 4
MSFlexGrid1.Rows = 1
End Sub
Private Sub Command1_Click()
With MSFlexGrid1
.AddItem ""
.TextMatrix(.Rows - 1, 1) = Text1.Text
.TextMatrix(.Rows - 1, 2) = Text2.Text
.TextMatrix(.Rows - 1, 3) = Text3.Text
End With
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub