Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single) Dim ColValue ColValue = DataGrid1.ColContaining(x) Debug.Print DataGrid1.Columns(ColValue).Text End Sub
Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) ColValue = DataGrid1.ColContaining(X) Me.Caption = DataGrid1.Columns(ColValue).Caption End Sub
Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Me.Caption = DataGrid1.Columns(DataGrid1.ColContaining(X)).Caption End Sub
好像还是显示上一列的 text
27和28都是你要的,需要放到MouseUp事件里,结贴吧
成功 感谢king06 和 dbcontrols 的指教 分享一下自己的代码Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) With DataGrid1 Select Case .ColContaining(X) Case 0 .AllowUpdate = False Case 1 .AllowUpdate = False Case 2 .AllowUpdate = False Case 3 .AllowUpdate = True Case 4 .AllowUpdate = True Case 5 .AllowUpdate = True End Select End With End Sub
无解就是解。如果一个功能很难实现或者没有,你就要考虑你的设计意图是否有问题。比如为什么一定要获得列名,为什么一定要用DataGrid。
001 张三 100 50
002 李四 78 56
...现在数据已经显示出来了
我想要 编号和姓名列 只读,而 补发和岗位扣可以输入更改。
查了好久,好像DATAGRID不能设置单独列的只读,只能设置整个表的只读。
我想了个变通的办法,就是鼠标点击编号和姓名 这两列时,让整个表只读
而点击补发和岗位扣时,让整个表可以更改。
这就需要鼠标点击相应列时,代码有个判断,到底点的是哪个列。如果是编号和姓名就将整个表只读,
如果是补发和岗位扣,就可以输入更改。Private Sub DataGrid1_Click()
这里面怎么写
下面这两句我会写
datagrid1.allowupdate=true
datagrid1.allowupdate=false
关键是怎么判断,点击的是那一列
End Sub
Private Sub DataGrid1_HeadClick(ByVal ColIndex As Integer)
Me.Caption = DataGrid1.Columns(ColIndex).Caption
End Sub
只是感觉有点绕远。 表格里的格,没有横纵坐标属性吗。
我记得好像 msflexgrid 的表格就可以通过 msflexgrid.row (行) msflexgrid.col (列)来定位。同时点击任意格,也可以返回行和列的属性
我试了一下 和dbcontrols 一样的意见 总是返回上次点击的列
这是为什么呢
Dim ColValue
ColValue = DataGrid1.ColContaining(x)
Debug.Print DataGrid1.Columns(ColValue).Text
End Sub
ColValue = DataGrid1.ColContaining(X)
Me.Caption = DataGrid1.Columns(ColValue).Caption
End Sub
Me.Caption = DataGrid1.Columns(DataGrid1.ColContaining(X)).Caption
End Sub
分享一下自己的代码Private Sub DataGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
With DataGrid1
Select Case .ColContaining(X)
Case 0
.AllowUpdate = False
Case 1
.AllowUpdate = False
Case 2
.AllowUpdate = False
Case 3
.AllowUpdate = True
Case 4
.AllowUpdate = True
Case 5
.AllowUpdate = True
End Select
End With
End Sub