Click here to Skip to main content
15,899,314 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with Structs Pin
JMichael246820-Oct-05 5:12
JMichael246820-Oct-05 5:12 
GeneralRe: Help with Structs Pin
JMichael246820-Oct-05 5:58
JMichael246820-Oct-05 5:58 
GeneralRe: Help with Structs Pin
S. Senthil Kumar20-Oct-05 6:06
S. Senthil Kumar20-Oct-05 6:06 
QuestionFileSystemWatcher not working over samba Pin
Dan Neely20-Oct-05 3:56
Dan Neely20-Oct-05 3:56 
AnswerRe: FileSystemWatcher not working over samba Pin
Dave Kreskowiak20-Oct-05 6:36
mveDave Kreskowiak20-Oct-05 6:36 
GeneralRe: FileSystemWatcher not working over samba Pin
Dan Neely20-Oct-05 7:03
Dan Neely20-Oct-05 7:03 
QuestionReading an eventlog from a remote computer Pin
Jaymz66620-Oct-05 3:46
Jaymz66620-Oct-05 3:46 
QuestionNumeric DataGridViewColumn Exception Pin
Greeky20-Oct-05 3:29
Greeky20-Oct-05 3:29 
i write a Numeric column class Set. But whenever i try to enter any value to numeric cell i got error and application restards itself. Exception is "TargetinvocationException ; Exception has been thrown by the target of an invocation."

NOTE : I create a table at run time, then i bind it to DataGridView. Table has one row at first.

CODE: : : : : :
Imports System<br />
Imports System.Windows.Forms<br />
<br />
#Region "NumericColumn Class"<br />
Public Class NumericColumn<br />
    Inherits DataGridViewColumn<br />
<br />
    Public Sub New()<br />
        MyBase.New(New NumericCell())<br />
    End Sub 'New<br />
<br />
<br />
    Public Overrides Property CellTemplate() As DataGridViewCell<br />
        Get<br />
            Return MyBase.CellTemplate<br />
        End Get<br />
        Set(ByVal value As DataGridViewCell)<br />
            ' Ensure that the cell used for the template is a NumericCell<br />
            If Not (value Is Nothing) And Not value.GetType().IsAssignableFrom(GetType(NumericCell)) Then<br />
                Throw New InvalidCastException("Must be a NumericCell")<br />
            End If<br />
            MyBase.CellTemplate = value<br />
        End Set<br />
    End Property<br />
End Class<br />
#End Region<br />
<br />
#Region "NumericCell Class"<br />
Public Class NumericCell<br />
    Inherits DataGridViewTextBoxCell<br />
<br />
<br />
    Public Sub New()<br />
<br />
    End Sub<br />
<br />
<br />
    Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)<br />
        MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)<br />
        Dim ctl As NumericEditingControl = CType(DataGridView.EditingControl, NumericEditingControl)<br />
        ctl.Text = Commas.SetComma(Me.Value)<br />
    End Sub<br />
<br />
<br />
    Public Overrides ReadOnly Property EditType() As Type<br />
        Get<br />
            ' Return the type of the editing contol that NumericCell uses.<br />
            Return GetType(NumericEditingControl)<br />
        End Get<br />
    End Property<br />
<br />
<br />
    Public Overrides ReadOnly Property ValueType() As Type<br />
        Get<br />
            ' Return the type of the value that NumericCell contains.<br />
            Return GetType(String)<br />
        End Get<br />
    End Property<br />
<br />
<br />
    Public Overrides ReadOnly Property DefaultNewRowValue() As Object<br />
        Get<br />
            ' Use the current date and time as the default value.<br />
            Return "0.00"<br />
        End Get<br />
    End Property<br />
End Class<br />
#End Region<br />
<br />
#Region "NumericEditingControl Class"<br />
Class NumericEditingControl<br />
    Inherits System.Windows.Forms.TextBox<br />
    Implements IDataGridViewEditingControl<br />
<br />
    Private dataGridViewControl As DataGridView<br />
    Private TextIsChanged As Boolean = False<br />
    Private rowIndexNum As Integer<br />
<br />
<br />
    Public Sub New()<br />
        Me.Text = "0.00"<br />
    End Sub 'New<br />
<br />
    ' Implements the IDataGridViewEditingControl.EditingControlFormattedValue property.<br />
    Public Property EditingControlFormattedValue() As Object Implements IDataGridViewEditingControl.EditingControlFormattedValue<br />
        Get<br />
            Return Me.Text<br />
        End Get<br />
        Set(ByVal value As Object)<br />
            'If TypeOf value Is [String] Then<br />
            Me.Text = Commas.SetComma(value) 'DateTime.Parse(CStr(value))<br />
            'End If<br />
        End Set<br />
    End Property<br />
<br />
<br />
    ' Implements the IDataGridViewEditingControl.GetEditingControlFormattedValue method.<br />
    Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object Implements IDataGridViewEditingControl.GetEditingControlFormattedValue<br />
        Return Me.Text<br />
    End Function 'GetFormattedValue<br />
<br />
<br />
    ' Implements the IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.<br />
    Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl<br />
        Me.Font = dataGridViewCellStyle.Font<br />
        'Me.NumericForeColor = dataGridViewCellStyle.ForeColor<br />
        'Me.NumericMonthBackground = dataGridViewCellStyle.BackColor<br />
    End Sub 'UseCellStyle<br />
<br />
    ' Implements the IDataGridViewEditingControl.EditingControlRowIndex property.<br />
    Public Property EditingControlRowIndex() As Integer Implements IDataGridViewEditingControl.EditingControlRowIndex<br />
        Get<br />
            Return rowIndexNum<br />
        End Get<br />
        Set(ByVal value As Integer)<br />
            rowIndexNum = value<br />
        End Set<br />
    End Property<br />
<br />
<br />
    ' Implements the IDataGridViewEditingControl.EditingControlWantsInputKey method.<br />
    Public Function EditingControlWantsInputKey(ByVal key As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements IDataGridViewEditingControl.EditingControlWantsInputKey<br />
<br />
        ' Let the DateTimePicker handle the keys listed.<br />
        Select Case key And Keys.KeyCode<br />
            Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp<br />
                Return True<br />
            Case Else<br />
                Return False<br />
        End Select<br />
    End Function 'IsInputKey<br />
<br />
<br />
    ' Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit method.<br />
    Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements IDataGridViewEditingControl.PrepareEditingControlForEdit<br />
        ' No preparation needs to be done.<br />
    End Sub 'PrepareForEdit<br />
<br />
    ' Implements the IDataGridViewEditingControl.RepositionEditingControlOnValueChange<br />
    ' property.<br />
    Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements IDataGridViewEditingControl.RepositionEditingControlOnValueChange<br />
        Get<br />
            Return False<br />
        End Get<br />
    End Property<br />
<br />
    ' Implements the IDataGridViewEditingControl.EditingControlDataGridView property.<br />
    Public Property EditingControlDataGridView() As DataGridView Implements IDataGridViewEditingControl.EditingControlDataGridView<br />
        Get<br />
            Return dataGridViewControl<br />
        End Get<br />
        Set(ByVal value As DataGridView)<br />
            dataGridViewControl = value<br />
        End Set<br />
    End Property<br />
<br />
    ' Implements the IDataGridViewEditingControl.EditingControlValueChanged property.<br />
    Public Property EditingControlValueChanged() As Boolean Implements IDataGridViewEditingControl.EditingControlValueChanged<br />
        Get<br />
            Return TextIsChanged<br />
        End Get<br />
        Set(ByVal value As Boolean)<br />
            TextIsChanged = value<br />
        End Set<br />
    End Property<br />
<br />
    ' Implements the IDataGridViewEditingControl.EditingPanelCursor method.<br />
    Public ReadOnly Property EditingPanelCursor() As Cursor Implements IDataGridViewEditingControl.EditingPanelCursor<br />
        Get<br />
            Return MyBase.Cursor<br />
        End Get<br />
    End Property<br />
    Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)<br />
        MyBase.OnTextChanged(e)<br />
        TextIsChanged = True<br />
        Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)<br />
    End Sub<br />
    Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)<br />
        Dim asciiInteger As Integer = Asc(e.KeyChar)<br />
        Select Case asciiInteger<br />
            Case 48 To 57 'Number<br />
                e.Handled = False<br />
            Case 8 'Backspace<br />
                e.Handled = False<br />
            Case 46 'Point<br />
                If Not Text.Length = 0 Then<br />
                    If Not Text.Contains(".") Then<br />
                        e.Handled = False<br />
                    Else<br />
                        e.Handled = True<br />
                    End If<br />
                Else<br />
                    e.Handled = True<br />
                End If<br />
            Case Else 'Yanlış Giriş<br />
                e.Handled = True<br />
        End Select<br />
    End Sub<br />
   <br />
End Class 'NumericEditingControl<br />
#End Region<br />
<br />
<br />
<br />

Questionquestion about drawing a menu Pin
Green Fuze20-Oct-05 3:05
Green Fuze20-Oct-05 3:05 
Questionquestion about drawing a menu Pin
Green Fuze20-Oct-05 3:05
Green Fuze20-Oct-05 3:05 
QuestionDataGridView columns Pin
Greeky20-Oct-05 2:53
Greeky20-Oct-05 2:53 
QuestionNt Event logger Pin
sharathgowda20-Oct-05 2:32
sharathgowda20-Oct-05 2:32 
AnswerRe: Nt Event logger Pin
S. Senthil Kumar20-Oct-05 4:36
S. Senthil Kumar20-Oct-05 4:36 
QuestionListView DisObeys!!! Pin
Ali Beirami20-Oct-05 2:12
Ali Beirami20-Oct-05 2:12 
QuestionStoping a running thread Pin
reederma20-Oct-05 2:04
reederma20-Oct-05 2:04 
AnswerRe: Stoping a running thread Pin
Tom Larsen20-Oct-05 3:27
Tom Larsen20-Oct-05 3:27 
GeneralRe: Stoping a running thread Pin
reederma20-Oct-05 3:43
reederma20-Oct-05 3:43 
GeneralRe: Stoping a running thread Pin
S. Senthil Kumar20-Oct-05 4:44
S. Senthil Kumar20-Oct-05 4:44 
GeneralRe: Stoping a running thread Pin
Tom Larsen20-Oct-05 8:21
Tom Larsen20-Oct-05 8:21 
Questioncode Pin
johan198520-Oct-05 1:44
johan198520-Oct-05 1:44 
AnswerRe: code Pin
enjoycrack20-Oct-05 7:08
enjoycrack20-Oct-05 7:08 
AnswerRe: code Pin
Matt Newman20-Oct-05 9:03
Matt Newman20-Oct-05 9:03 
AnswerRe: code Pin
Matt Gerrans20-Oct-05 13:17
Matt Gerrans20-Oct-05 13:17 
GeneralRe: code Pin
tatchung20-Oct-05 15:19
tatchung20-Oct-05 15:19 
QuestionHow to Select Acroos All pages in Grid Pin
kris8220-Oct-05 1:19
kris8220-Oct-05 1:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.