按钮列的应用

时间:2007-01-21 14:07:42   来源:  作者:  点击:次  出处:技术无忧
关键字:按钮

      '请空单元格

        g.FillRectangle(New SolidBrush(BackColor), bounds)

        ' 绘制值 

        Dim s As String = Me.GetColumnValueAtRow([source], rowNum).ToString() 'parent[rowNum, 0].ToString() + ((parent[rowNum, 1].ToString())+ "  ").Substring(0,2);

      

        g.DrawString(s, parent.Font, New SolidBrush(ForeColor), bounds.X, bounds.Y)

        Dim bm As Bitmap

        If m_Row = rowNum Then bm = Me.m_FacePressed Else bm = Me.m_Face

        g.DrawImage(bm, bounds.Right - bm.Width, bounds.Y)

    End Sub

End Class

 

调用代码: 

Private Function getdatagridstyle(ByVal table As DataTable) As DataGridTableStyle

        Dim style As New DataGridTableStyle()

        style.MappingName = table.TableName

        style.RowHeaderWidth = 15

        Dim i As Integer

        For i = 0 To table.Columns.Count - 1

            If i = 1 Then

                Dim textButtonColStyle As New mybuttondatagridtablestyle1(i) 'pass the column#

                textButtonColStyle.HeaderText = table.Columns(i).ColumnName

                textButtonColStyle.MappingName = table.Columns(i).ColumnName

                'hookup our cellbutton handler...

                AddHandler textButtonColStyle.CellButtonClicked, AddressOf HandleCellButtonClick

                style.GridColumnStyles.Add(textButtonColStyle)

                'hook the mouse handlers

                AddHandler DataGrid1.MouseDown, AddressOf textButtonColStyle.HandleMouseDown

                AddHandler DataGrid1.MouseUp, AddressOf textButtonColStyle.HandleMouseUp

            Else

                Dim c As New DataGridTextBoxColumn()

                c.HeaderText = table.Columns(i).ColumnName

                c.MappingName = table.Columns(i).ColumnName

                style.GridColumnStyles.Add(c)

            End If

        Next

        Return style

    End Function

    Private Sub HandleCellButtonClick(ByVal sender As Object, ByVal e As DataGridCellButtonClickEventArgs)

        MessageBox.Show(("row " + e.RowIndex.ToString() + "  col " + e.ColIndex.ToString() + " clicked."))

    End Sub

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

WWW.pC51.Net


相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

300x250广告位招租