Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataGridTextBoxColumn Class
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00744758
Message ID:
00744823
Views:
8
Wonderful !!! Do you have c# code by any chance?

Thanks a lot.

>Hi Jayesh,
>
>You will need to create your own DataGridTextBoxColumn class that uses your own Textbox. For example, here is a set of code that creates a subclassed Textbox with a Button for a column:
>
>
>Imports Microsoft.VisualBasic
>Imports System
>Imports System.Drawing
>Imports System.Windows.Forms
>
>Public Class DataGridTextBoxButtonColumn
>    Inherits DataGridTextBoxColumn
>
>    Private _source As System.Windows.Forms.CurrencyManager
>    Private _rowNum As Integer
>    Private _isEditing As Boolean
>    Private _Updating As Boolean
>
>    Private ButtonClicked As Boolean
>    Private MouseOver As Boolean
>
>    Public Shared _RowCount As Integer
>
>    Public TB As NoKeyUpTextBox
>
>    Public myButton As Button
>
>    Public Sub New()
>        _source = Nothing
>        _RowCount = -1
>
>        TB = New NoKeyUpTextBox()
>        myButton = New Button()
>        myButton.Text = "..."
>        TB.Visible = False
>        myButton.Visible = False
>
>'AddHandler Me.TextBox.Leave, AddressOf TBLeave ' .Leave, AddressOf TBLeave
>
>        AddHandler Me.TextBox.TextChanged, AddressOf Update
>
>        AddHandler Me.TB.Enter, AddressOf TBEnter
>        AddHandler TB.Leave, AddressOf TBLeave ' .Leave, AddressOf TBLeave
>
>        AddHandler TB.TextChanged, AddressOf TBChange
>
>        AddHandler TB.MouseLeave, AddressOf MouseOut
>        AddHandler TB.MouseEnter, AddressOf MouseIn
>        AddHandler myButton.MouseEnter, AddressOf MouseIn
>        AddHandler myButton.MouseLeave, AddressOf MouseOut
>
>        AddHandler myButton.Click, AddressOf ButtonClick
>        AddHandler myButton.Leave, AddressOf TBLeave
>    End Sub 'New
>
>    Public Sub Update(ByVal sender As Object, ByVal e As System.EventArgs)
>        If ButtonClicked Then
>            ButtonClicked = False
>            Me.TB.Text = Me.TextBox.Text
>        End If
>    End Sub
>
>    Private Sub MouseOut(ByVal sender As Object, ByVal e As System.EventArgs)
>        MouseOver = False
>    End Sub
>
>    Private Sub MouseIn(ByVal sender As Object, ByVal e As System.EventArgs)
>        MouseOver = True
>    End Sub
>
>    Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
>        TB.Show()
>        ButtonClicked = True
>        RaiseEvent ColumnButtonClick()
>    End Sub
>
>    Public Event ColumnButtonClick()
>
>    Private Sub TBChange(ByVal sender As Object, ByVal e As EventArgs)
>        If _Updating Then Exit Sub
>        _isEditing = True
>        MyBase.ColumnStartedEditing(sender)
>    End Sub
>
>    Private Sub TBEnter(ByVal sender As Object, ByVal e As EventArgs)
>        System.Diagnostics.Debug.WriteLine("TBEnter")
>        TB.Focus()
>    End Sub
>
>    Private Sub TBLeave(ByVal sender As Object, ByVal e As EventArgs)
>
>        If myButton.MouseButtons = MouseButtons.Left Then
>            If MouseOver Then
>                Exit Sub
>            End If
>        End If
>
>        If _isEditing Then
>            SetColumnValueAtRow(_source, _rowNum, TB.Text)
>            _isEditing = False
>            Invalidate()
>        End If
>        TB.Hide()
>        myButton.Hide()
>AddHandler Me.DataGridTableStyle.DataGrid.Scroll, New EventHandler(AddressOf
>HandleScroll)
>    End Sub 'LeaveTB
>
>    Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)
>        If TB.Visible Then
>            TB.Hide()
>            myButton.Hide()
>        End If
>    End Sub 'HandleScroll
>
>Protected Overloads Overrides Sub Edit(ByVal [source] As
>System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds As
>System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText As
>String, ByVal cellIsVisible As Boolean)
>
>MyBase.Edit([source], rowNum, bounds, [readOnly], instantText, cellIsVisible)
>
>        _rowNum = rowNum
>        _source = [source]
>
>        TB.Visible = False
>        TB.BorderStyle = BorderStyle.Fixed3D
>        TB.Parent = Me.TextBox.Parent
>        TB.Height = Me.TextBox.Height
>
>        TB.Width = Me.TextBox.Width
>        TB.BorderStyle = BorderStyle.None
>
>        TB.Top = Me.TextBox.Top
>        TB.Left = Me.TextBox.Left
>
>        _Updating = True
>        TB.Text = Me.TextBox.Text
>        TB.Visible = True
>        _Updating = False
>
>        Me.TextBox.Visible = False
>
>        AddHandler Me.DataGridTableStyle.DataGrid.Scroll, AddressOf HandleScroll
>
>        TB.BringToFront()
>        TB.Focus()
>
>        myButton.Font = Me.TextBox.Font
>        myButton.TextAlign = ContentAlignment.MiddleCenter
>
>        myButton.Visible = False
>        myButton.Parent = Me.TextBox.Parent
>        myButton.BackColor = System.Drawing.SystemColors.Control
>
>        myButton.Top = Me.TextBox.Top - 2
>        myButton.Height = Me.TB.Height + 2
>        myButton.Width = 22
>        myButton.Left = Me.TextBox.Left + Me.TextBox.Width - myButton.Width
>
>        myButton.BringToFront()
>        myButton.Visible = True
>        TB.Visible = True
>        TB.Focus()
>
>    End Sub 'Edit
>
>Protected Overrides Function Commit(ByVal dataSource As
>System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
>
>        If _isEditing Then
>            _isEditing = False
>            SetColumnValueAtRow(dataSource, rowNum, TB.Text)
>        End If
>
>        MyBase.Commit(dataSource, rowNum)
>        Return True
>    End Function 'Commit
>
>    Protected Overrides Sub ConcedeFocus()
>        MyBase.ConcedeFocus()
>    End Sub 'ConcedeFocus
>
>End Class
>
>Public Class NoKeyUpTextBox
>    Inherits TextBox
>    Private WM_KEYUP As Integer = &H101
>
>    Public Sub New()
>        Me.Multiline = True
>    End Sub
>
>    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
>        If m.Msg = WM_KEYUP Then
>            'ignore keyup to avoid problem with tabbing & dropdownlist;
>            Return
>        End If
>        MyBase.WndProc(m)
>    End Sub 'WndProc
>End Class 'NoKeyUpCombo
>
>
>>DataGridTextBoxColumn Class has "TextBox" property, which holds reference to the TextBox control. It is a read-only property. Is there a way where I can assign my own textbox class to it?
- Jayesh
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform