请问如何实现这样的功能??

ada518 2004-10-26 04:48:52
ADO 连接 两个DATAGRID(或者其他)
在其中一个DATAGRID 的一行双击,该行从改DATAGRID删除,添加到另外一个DATAGRID上

请问可以实现吗?
...全文
80 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ABCatai 2004-11-10
本人强烈推荐用MS Flexgrid写
以下是我曾写的一段代码其中就有双击使单元格获得某值和清空的功能

Private Sub Fgrid1_DblClick()
If Fgrid1.Col = 3 Then
Select Case Fgrid1.Row
Case 1
If Fgrid1.Text = "" Then
Fgrid1.Text = "参选"
s(1) = "151"
x = x + 1
Else
Fgrid1.Text = ""
s(1) = ""
x = x - 1
End If
Case 2
If Fgrid1.Text = "" Then
Fgrid1.Text = "参选"
s(2) = "152"
x = x + 1
Else
Fgrid1.Text = ""
s(2) = ""
x = x - 1
End If
Case 3
If Fgrid1.Text = "" Then
Fgrid1.Text = "参选"
s(3) = "121"
x = x + 1
Else
Fgrid1.Text = ""
s(3) = ""
x = x - 1
End If
Case 4
If Fgrid1.Text = "" Then
Fgrid1.Text = "参选"
s(4) = "122"
x = x + 1
Else
Fgrid1.Text = ""
s(4) = ""
x = x - 1
End If
End Select
StatusBar1.Panels.Item(1) = "参选班级:027" & s(1) & " " & s(2) & " " & s(3) & " " & s(4)
End If
End Sub
回复
xiaoxiaoP 2004-10-27
还是用FLEXGRID吧,你说的这种效果我常用它来实现。
三个frame1()中,每个容一个MSFlexGrid1()

Private Sub MSFlexGrid1_DblClick(Index As Integer)
Select Case Index
Case 0
I = MSFlexGrid1(2).Rows
If MSFlexGrid1(0).row = 0 Then Exit Sub
If Trim(MSFlexGrid1(0).TextArray(MSFlexGrid1(0).Cols * MSFlexGrid1(0).row + 1)) = "" Then Exit Sub
MSFlexGrid1(2).Rows = I + 1
MSFlexGrid1(2).TextArray(I * 3 + 0) = "-"
MSFlexGrid1(2).TextArray(I * 3 + 1) = MSFlexGrid1(0).TextArray(MSFlexGrid1(0).Cols * MSFlexGrid1(0).row + 1)
MSFlexGrid1(2).TextArray(I * 3 + 2) = MSFlexGrid1(0).TextArray(MSFlexGrid1(0).Cols * MSFlexGrid1(0).row + 2)
Frame1(2).Caption = "准备加"
Frame1(2).ForeColor = &H8000&

Case 1
I = MSFlexGrid1(2).Rows
If MSFlexGrid1(1).row = 0 Then Exit Sub
If Trim(MSFlexGrid1(1).TextArray(MSFlexGrid1(1).Cols * MSFlexGrid1(1).row + 1)) = "" Then Exit Sub
MSFlexGrid1(2).Rows = I + 1
MSFlexGrid1(2).TextArray(I * 3 + 0) = "-"
MSFlexGrid1(2).TextArray(I * 3 + 1) = MSFlexGrid1(1).TextArray(MSFlexGrid1(1).Cols * MSFlexGrid1(1).row + 1)
MSFlexGrid1(2).TextArray(I * 3 + 2) = MSFlexGrid1(1).TextArray(MSFlexGrid1(1).Cols * MSFlexGrid1(1).row + 2)
Frame1(2).Caption = "准备取消"
Frame1(2).ForeColor = &HFF&

Case 2
j = MSFlexGrid1(2).Rows
k = MSFlexGrid1(2).row
If Trim(MSFlexGrid1(1).TextArray(MSFlexGrid1(2).Cols * MSFlexGrid1(2).row + 1)) = "" Then Exit Sub
If k = 0 Then Exit Sub
For jFor = k * 3 To (j - 1) * 3 - 1
MSFlexGrid1(2).TextArray(jFor) = MSFlexGrid1(2).TextArray(jFor + 3)
Next jFor
MSFlexGrid1(2).Rows = j - 1

End Select
End Sub
试试效果吧。
回复
creazyfish 2004-10-27
今天晚上,我回去写个好的,再发给大家,ok?
回复
creazyfish 2004-10-27
写的很匆忙,可能会有些问题,有问题给我留言。大概的意思就是这样的
Dim mysql As String
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim con As New ADODB.Connection
Dim strcon As String

Private Sub Command1_Click()
With rs2
.AddNew
.Fields(0).Value = rs1.Fields(0).Value
.Fields(1).Value = rs1.Fields(1).Value
.Fields(2).Value = rs1.Fields(2).Value
.Fields(3).Value = rs1.Fields(3).Value
.Update
End With
With rs1
.Delete adAffectCurrent
.Update
End With
Me.Grid1.DataSource = rs1
Me.Grid1.DataSource = rs2
End Sub

Private Sub Form_Load()

strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PER\Programe\demo\2\Attendance.mdb;Persist Security Info=False"

mysql = "select * from Employee"

con.Open strcon
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.Open mysql, con, adOpenDynamic, adLockPessimistic

With rs1
.Fields.Append "EmployeeNo", adBSTR, 50, adFldIsNullable
.Fields.Append "EmployeeName", adBSTR, 50, adFldIsNullable
.Fields.Append "PassWord", adBSTR, 20, adFldIsNullable
.Fields.Append "Level", adBSTR, 2, adFldIsNullable
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
End With

With rs2
.Fields.Append "EmployeeNo", adBSTR, 50, adFldIsNullable
.Fields.Append "EmployeeName", adBSTR, 50, adFldIsNullable
.Fields.Append "PassWord", adBSTR, 20, adFldIsNullable
.Fields.Append "Level", adBSTR, 2, adFldIsNullable
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open , , 1, 3
End With


Set rs1 = rs

Set Me.Grid1.DataSource = rs1
Grid1.Refresh

Set Me.Grid2.DataSource = rs2
Grid2.Refresh

End Sub
回复
ABCatai 2004-10-27
楼上的我也要一个
回复
creazyfish 2004-10-27
你稍等,我写一个
回复
ada518 2004-10-27
楼上的 具体怎么写啊?
我这两个查询都是一个表 只是查询条件不一样而已
回复
creazyfish 2004-10-26
可以啊,直接用recordset的.add & .delete就可以实现了,然后用.update,最后重新绑定就ok!
回复
cpio 2004-10-26
用FLEXGRID吧,DATAGRID好像可以控件的地方很少
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告