VBGood网站全文搜索 Google

首页 - 经验之谈 - 快速定制DBGrid单元对话框
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11117, 日期:2000-10-19
Quick Custom Dialogs for DBGrid Cells
By Mike Amundsen, mike@amundsen.com, http://www.amundsen.com
It注释:s easy to add custom input dialogs to all the cells in the Microsoft Data Bound Grid control.

First, add a DBGrid control and Data control to your form. Next, set the DatabaseName and RecordSource properties of the data control to a valid database and table ("biblio.mdb" and "Publishers" for example). Then set the DataSource property of the DBGrid control to Data1 (the data control).

Now add the following code to your form.

注释: general declaration area
Dim strDBGridCell As String

Private Sub DBGrid1_AfterColEdit(ByVal ColIndex As Integer)
  DBGrid1.Columns(ColIndex) = strDBGridCell
End Sub

Private Sub DBGrid1_BeforeColEdit(ByVal ColIndex As Integer, ByVal KeyAscii As Integer, Cancel As Integer)
  strDBGridCell = InputBox("Edit DBGrid Cell:", , DBGrid1.Columns(ColIndex))
End Sub

Now whenever you attempt to edit any cell in the DBGrid, you注释:ll see the InputBox prompt you for input. You can replace the InputBox with any other custom dialog you wish to build.