Public Class NEwfp07

    Private V_enterToTab As Boolean = True
    Private V_DeleteKey As Boolean = True
    Private V_CurrentDel As Boolean = True
    Private V_FIRSTINDEX As Integer = 0
    Private V_NextRowindex As Integer = -1
    Private A_Ubound As New ArrayList
    Private V_SpaceEdit As Boolean = True
    Private V_sameRHeight As Boolean = True
    Private v_Checkbox_ColIndex As Int16 = -1
    Private v_ACellposLabel As ToolStripStatusLabel = Nothing
    Private v_ACellImeLabel As ToolStripStatusLabel = Nothing
    Private v_AMessageLabel As ToolStripStatusLabel = Nothing
    Public 전줄값복사() As String
    Public 한글필드() As String
    Public 다음줄필드명 As String

    Private v_AAutoAddrowInLast As ToolStripButton = Nothing
    Private V_AButtonAdd As ToolStripButton = Nothing '//추가버튼
    'Private v_AButtonInsert As ToolStripButton = Nothing   '//삽입버튼

    Public Event Arin_DataChanged(ByVal sender As Object, ByVal Status As String) '//미사용
    Public Event Arin_AddRow(ByVal sender As Object, ByVal Status As String)  '//미사용
    Public Event Arin_InsertRow(ByVal sender As Object, ByVal Status As String) '//미사용
    Public Event Arin_AddLog(ByVal sender As Object, ByVal msg As String)
    Public Event Arin_Before_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)  '//키보드가 눌럿을떄 먼저 실행할 함수(뷰의 keydown은 나중에 일어난다)
    Public Event Arin_Before_EditModeOff(ByVal sender As Object, ByVal e As System.EventArgs)
    Public Event Arin_LovCodeEntry(ByVal sender As Object, ByVal e As System.EventArgs)

    '<System.ComponentModel.Description("한줄추가에 사용할 버튼입니다.")> _
    '   Public Property AButtonAdd() As ToolStripButton
    '    Get
    '        Return Me.V_AButtonAdd
    '    End Get
    '    Set(ByVal value As ToolStripButton)
    '        Me.V_AButtonAdd = value
    '    End Set
    'End Property


    <System.ComponentModel.Description("더이상데이터가없는 마지막줄일때 자동으로 해당 버튼을 클릭해줍니다.")> _
   Public Property AEnterToNextItem() As Boolean
        Get
            Return Me.V_enterToTab
        End Get
        Set(ByVal value As Boolean)
            Me.V_enterToTab = value
        End Set
    End Property

    <System.ComponentModel.Description("더이상데이터가없는 마지막줄일때 자동으로 해당 버튼을 클릭해줍니다.")> _
    Public Property AAutoAddrowInLast() As ToolStripButton
        Get
            Return Me.v_AAutoAddrowInLast
        End Get
        Set(ByVal value As ToolStripButton)
            Me.v_AAutoAddrowInLast = value
        End Set
    End Property

    Private Sub Disp_Msg(ByVal msgstr As String)
        If Not v_AMessageLabel Is Nothing Then
            v_AMessageLabel.Text = "[뷰메세지] : " & msgstr & Space(1) & Now.ToString
            v_AMessageLabel.ForeColor = Color.Green
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)

        End If

    End Sub
    Public Sub ArinSearch()
        Dim Frow, Fcol As Integer
        Me.Search(Me.ActiveSheetIndex, InputBox("선택된 열에서 검색할 문자를 입력하세요.", "검색문자를 입력하세요"), False, False, False, True, True, False, False, 0, 0, Frow, Fcol)
        If Frow >= 0 AndAlso Fcol >= 0 Then '//검색됫다면
            Me.ActiveSheet.SetActiveCell(Frow, Fcol)
            SendKeys.Send("{ENTER}")
        End If
    End Sub

    <System.ComponentModel.Description("뷰에서 발생하는 메세지를 표시할 라벨입니다.")> _
      Public Property AMessageLabel() As ToolStripStatusLabel
        Get
            Return Me.v_AMessageLabel
        End Get
        Set(ByVal value As ToolStripStatusLabel)
            Me.v_AMessageLabel = value
        End Set
    End Property
    <System.ComponentModel.Description("현재 셀위치를 표시해줄 스텟라벨을 선택합니다")> _
    Public Property ACellposLabel() As ToolStripStatusLabel
        Get
            Return Me.v_ACellposLabel
        End Get
        Set(ByVal value As ToolStripStatusLabel)
            Me.v_ACellposLabel = value
        End Set
    End Property

    <System.ComponentModel.Description("현재 IMe 입력상태를 표시할 라벨을 선택합니다")> _
   Public Property ACellImeLabel() As ToolStripStatusLabel
        Get
            Return Me.v_ACellImeLabel
        End Get
        Set(ByVal value As ToolStripStatusLabel)
            Me.v_ACellImeLabel = value
        End Set
    End Property

    <System.ComponentModel.Description("선택용 체크박스의 인덱스번호를 입력하세요")> _
   Public Property ACheckBox_ColIndex() As Int16
        Get
            Return v_Checkbox_ColIndex
        End Get
        Set(ByVal value As Int16)
            v_Checkbox_ColIndex = value
        End Set
    End Property

    <System.ComponentModel.Description("줄너비가 변경될때 모두 같이 변경됩니다")> _
      Public Property ASameRowheight() As Boolean
        Get
            Return V_sameRHeight
        End Get
        Set(ByVal value As Boolean)
            V_sameRHeight = value
        End Set
    End Property



    <System.ComponentModel.Description("스페이스키를 누르면 편집모드로 들어갑니다")> _
   Public Property AEditFromSpace() As Boolean
        Get
            Return V_SpaceEdit
        End Get
        Set(ByVal value As Boolean)
            V_SpaceEdit = value
        End Set
    End Property


    ''' <summary>
    ''' 중복검사루틴에서 사용하는 함수
    ''' </summary>
    ''' <param name="num1"></param>
    ''' <param name="num2"></param>
    ''' <param name="Source"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function DupCheckBool(ByVal num1 As Integer, ByVal num2 As Integer, ByVal Source As ArrayList) As Boolean
        If Source Is Nothing Then Return False
        If Source.IndexOf(num1) >= 0 Then Return True
        If Source.IndexOf(num2) >= 0 Then Return True
        Return False
    End Function



    ''' <summary>
    ''' 중복된 데이터를 검색합니다. startindex = 시작할 줄번호,endindex = 종료할 줄번호, source 검색원본의 열번호들, target 검색대상의 열번호들
    ''' 검색완료후 전체 중복된 갯수를 리턴합니다.
    ''' </summary>
    ''' <param name="StartIndex"></param>
    ''' <param name="EndIndex"></param>
    ''' <param name="Source"></param>
    ''' <param name="Tartger"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ADupCheck(ByVal StartIndex As Integer, ByVal EndIndex As Integer, ByVal Source() As Short, ByVal Tartger() As Short, Optional ByVal CheckColnum As Short = -1, Optional ByVal CheckValue As Boolean = True, Optional ByVal 설명열 As Short = -1, Optional ByVal 설명 As String = "", Optional ByVal PBar As ProgressBar = Nothing) As ArrayList
        '''''검색방법은 1번개체부터 마지막개체까지 풀루프를 돌면서 동일한 놈을 찾는다.
        Dim 원본, 대상 As String 'New System.Text.StringBuilder
        Dim DupList As New ArrayList
        Dim fcnt As Integer = 0

        If Not PBar Is Nothing Then
            PBar.Value = StartIndex
            PBar.Minimum = StartIndex
            PBar.Maximum = EndIndex
        End If

        'NOTICE("중복되는 [전주번호]를 찾는중입니다...", Me.lb_msg)
        'Me.Invalidate()
        'MsgBox(Me.ActiveSheet.RowCount)



        For A As Integer = StartIndex To EndIndex
            'MsgBox(StartIndex & "/" & EndIndex)

            원본 = ""
            For Each T As Short In Source
                원본 &= Me.ActiveSheet.Cells(A, T).Value
            Next

            If 원본.ToString <> "" Then
                For B As Integer = StartIndex To EndIndex
                    If A <> B AndAlso Not DupCheckBool(A, B, DupList) Then   '//같은라인은 피하고 그렇지 않은 라인의 번호를 확인한다.
                        대상 = ""
                        For Each T As Short In Tartger
                            대상 &= Me.ActiveSheet.Cells(B, T).Value
                        Next
                        'MsgBox(원본 & "/" & 대상)

                        If 원본.ToString = 대상.ToString Then
                            'MsgBox(원본)
                            If DupList Is Nothing Then DupList = New ArrayList
                            DupList.Add(A)
                            DupList.Add(B)

                            fcnt += 1
                            If CheckColnum > -1 Then
                                Me.ActiveSheet.Cells(A, CheckColnum).Value = CheckValue
                                Me.ActiveSheet.Cells(B, CheckColnum).Value = CheckValue
                            End If

                            If 설명열 > -1 Then
                                Me.ActiveSheet.Cells(A, 설명열).Value &= "[" & A & "/" & B & "]" & 설명 '//설명하도록햇을시에
                                Me.ActiveSheet.Cells(B, 설명열).Value &= "[" & A & "/" & B & "]" & 설명 '//설명하도록햇을시에
                            End If

                        End If
                    End If
                Next
            End If
            If Not PBar Is Nothing Then
                If PBar.Value < PBar.Maximum Then PBar.Value += 1
                Me.Invalidate()
            End If
        Next
        Return DupList

        'NOTICE("[전주번호] 중복검사 완료(" & fcnt & "개의 데이터를 찾았습니다)", Me.lb_msg)
    End Function


    Public Function ADupCheck2(ByVal StartIndex As Integer, ByVal EndIndex As Integer, ByVal Source() As Short, ByVal Tartger() As Short, Optional ByVal CheckColnum As Short = -1, Optional ByVal PBar As ProgressBar = Nothing) As Integer
        '''''검색방법은 1번개체부터 마지막개체까지 풀루프를 돌면서 동일한 놈을 찾는다.
        Dim 원본, 대상 As String 'New System.Text.StringBuilder
        Dim fcnt As Integer = 0

        If Not PBar Is Nothing Then
            PBar.Value = StartIndex
            PBar.Minimum = StartIndex
            PBar.Maximum = EndIndex
        End If

        For A As Integer = StartIndex To EndIndex
            원본 = ""
            For Each T As Short In Source
                원본 &= Me.ActiveSheet.Cells(A, T).Value
            Next
            If 원본.Trim.ToString <> "" Then
                For B As Integer = StartIndex To EndIndex
                    If A <> B Then   '//같은라인은 피하고 그렇지 않은 라인의 번호를 확인한다.
                        대상 = ""
                        For Each T As Short In Tartger
                            대상 &= Me.ActiveSheet.Cells(B, T).Value
                        Next
                        If 원본.Trim.ToString = 대상.Trim.ToString Then
                            fcnt += 1
                            If CheckColnum > -1 Then
                                Me.ActiveSheet.Cells(A, CheckColnum).Value = True
                                Me.ActiveSheet.Cells(B, CheckColnum).Value = True
                            End If
                        End If
                    End If
                Next
            End If
            If Not PBar Is Nothing Then
                If PBar.Value < PBar.Maximum Then PBar.Value += 1
                Me.Invalidate()
            End If
        Next
        Return fcnt
        'NOTICE("[전주번호] 중복검사 완료(" & fcnt & "개의 데이터를 찾았습니다)", Me.lb_msg)
    End Function


    ''' <summary>
    ''' 중복검사 같은줄
    ''' </summary>
    ''' <param name="StartIndex"></param>
    ''' <param name="EndIndex"></param>
    ''' <param name="Source"></param>
    ''' <param name="Tartger"></param>
    ''' <param name="CheckColnum"></param>
    ''' <param name="PBar"></param>
    ''' <param name="TrueDirection"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AdupCheckSR(ByVal StartIndex As Integer, ByVal EndIndex As Integer, ByVal Source() As Short, ByVal Tartger() As Short, Optional ByVal CheckColnum As Short = -1, Optional ByVal PBar As ProgressBar = Nothing, Optional ByVal TrueDirection As Boolean = True) As Integer
        Dim 원본, 대상 As String 'New System.Text.StringBuilder
        Dim fcnt As Integer = 0
        Dim Can As Boolean = False
        If Not PBar Is Nothing Then : PBar.Value = StartIndex : PBar.Minimum = StartIndex : PBar.Maximum = EndIndex : End If

        For A As Integer = StartIndex To EndIndex
            원본 = "" : 대상 = ""
            Can = False
            For Each T As Short In Source
                원본 &= Me.ActiveSheet.Cells(A, T).Value
            Next
            For Each T As Short In Tartger
                대상 &= Me.ActiveSheet.Cells(A, T).Value
            Next

            If 원본.Trim.ToString <> "" Then
                If TrueDirection = True Then
                    If 원본.Trim.ToString = 대상.Trim.ToString Then Can = True
                Else
                    If 원본.Trim.ToString <> 대상.Trim.ToString Then Can = True
                End If
                If Can Then
                    fcnt += 1
                    If CheckColnum > -1 Then Me.ActiveSheet.Cells(A, CheckColnum).Value = True
                End If

            End If
            If Not PBar Is Nothing Then
                If PBar.Value < PBar.Maximum Then PBar.Value += 1
                Me.Invalidate()
            End If
        Next
        Return fcnt

    End Function

    ''' <summary>
    ''' 중복검사 같은줄 공란포함
    ''' </summary>
    ''' <param name="StartIndex"></param>
    ''' <param name="EndIndex"></param>
    ''' <param name="Source"></param>
    ''' <param name="Tartger"></param>
    ''' <param name="CheckColnum"></param>
    ''' <param name="PBar"></param>
    ''' <param name="TrueDirection"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ADupCheckSr_inBlank(ByVal StartIndex As Integer, ByVal EndIndex As Integer, ByVal Source() As Short, ByVal Tartger() As Short, Optional ByVal CheckColnum As Short = -1, Optional ByVal PBar As ProgressBar = Nothing, Optional ByVal TrueDirection As Boolean = True) As Integer
        Dim 원본, 대상 As String 'New System.Text.StringBuilder
        Dim fcnt As Integer = 0
        Dim Can As Boolean = False
        If Not PBar Is Nothing Then : PBar.Value = StartIndex : PBar.Minimum = StartIndex : PBar.Maximum = EndIndex : End If

        For A As Integer = StartIndex To EndIndex
            원본 = "" : 대상 = ""
            Can = False
            For Each T As Short In Source
                원본 &= Me.ActiveSheet.Cells(A, T).Text
            Next
            For Each T As Short In Tartger
                대상 &= Me.ActiveSheet.Cells(A, T).Text
            Next

            If TrueDirection = True Then
                If 원본.Trim.ToString = 대상.Trim.ToString Then Can = True
            Else
                If 원본.Trim.ToString <> 대상.Trim.ToString Then Can = True
            End If

            If Can Then
                fcnt += 1
                If CheckColnum > -1 Then Me.ActiveSheet.Cells(A, CheckColnum).Value = True
            End If

            If Not PBar Is Nothing Then
                If PBar.Value < PBar.Maximum Then PBar.Value += 1
                Me.Invalidate()
            End If
        Next
        Return fcnt

    End Function


    ''' <summary>
    ''' 현재위치 위에 새로운 행을 추가합니다(바운드 적용됨)
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AInsertNewRow()
        If Not Me.Focused Then Me.Focus()
        Me.ActiveSheet.Rows.Add(Me.ActiveSheet.ActiveRowIndex, 1)
        Me.ActiveSheet.SetActiveCell(Me.ActiveSheet.ActiveRowIndex, Me.AFirstColumn_Index)
    End Sub

    ''' <summary>
    ''' 마지막에 새로운 행을 추가합니다(바운드 적용됨)
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AAddNewRow()
        If Not Me.Focused Then Me.Focus()
        'Me.ActiveSheet.RowCount += 1
        Me.ActiveSheet.Rows.Add(Me.ActiveSheet.RowCount, 1)
        Me.ActiveSheet.SetActiveCell(Me.ActiveSheet.RowCount, Me.AFirstColumn_Index)
        SendKeys.Send("{UP}")
        SendKeys.Send("{DOWN}")
    End Sub

    ''' <summary>
    ''' 마지막에 새로운 행을 추가합니다.(바운드적용안됨)
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AAddNewRowU()
        If Not Me.Focused Then Me.Focus()
        Dim Idx As Integer
        Me.ActiveSheet.AddUnboundRows(Me.ActiveSheet.RowCount, 1)
        Idx = Me.ActiveSheet.RowCount - 1
        Me.ActiveSheet.Rows(Idx).Tag = "UNBOUND"
        Me.ActiveSheet.SetActiveCell(Me.ActiveSheet.RowCount, AFirstColumn_Index)
        SendKeys.Send("{ENTER}")
    End Sub

    <System.ComponentModel.Description("줄바꿈을 할 열 번호입니다")> _
      Public Property ANextRow_ColIndex() As Integer
        Get
            Return V_NextRowindex
        End Get
        Set(ByVal value As Integer)
            V_NextRowindex = value
        End Set
    End Property
    <System.ComponentModel.Description("줄이 바뀌었을때 커서가 위치할 시작 값입니다.")> _
   Public Property AFirstColumn_Index() As Integer
        Get
            Return V_FIRSTINDEX

        End Get
        Set(ByVal value As Integer)
            V_FIRSTINDEX = value
        End Set
    End Property

    <System.ComponentModel.Description("Del 키를 누를시 커서가 위치한 셀의 값을 초기합니다")> _
Public Property ADeleteCell() As Boolean
        Get
            Return V_CurrentDel

        End Get
        Set(ByVal value As Boolean)
            V_CurrentDel = value
        End Set
    End Property

    <System.ComponentModel.Description("Shift+Del 키를 누를시 해당 줄을 삭제합니다.")> _
       Public Property ADeleteRow() As Boolean
        Get
            Return V_DeleteKey

        End Get
        Set(ByVal value As Boolean)
            V_DeleteKey = value
        End Set
    End Property



    ''' <summary>
    ''' 커서를 다음셀로 이동 (문제가 좀 있다 열너비 0인것들에대해서
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ANext_Cell()
        '//커서를 다음셀로 이동한다. 다음셀의 너비가 0이거나 tabstop 이 false 이면 그 다음으로 이동한다.
        SendKeys.Send(vbTab)
        Return

        '        Dim index As Integer = 0
        'Start:
        '        index += 1
        '        If Me.ActiveColumnindex = Me.ActiveSheet.ColumnCount - 1 Then Return '//현재열이 마지막열이라면 빠진다.
        '        If Me.ActiveColumnindex + index > Me.ActiveSheet.Columns.Count Then Return

        '        If Me.ActiveSheet.Columns(Me.ActiveColumnindex + index).Width = 0 Or Me.ActiveSheet.Columns(Me.ActiveColumnindex + index).TabStop = False Then
        '            GoTo Start
        '        End If

        '        Me.ActiveSheet.SetActiveCell(Me.ActiveRowindex, Me.ActiveColumnindex + index)

        '        Dim Ee As New FarPoint.Win.Spread.EnterCellEventArgs(Nothing, Me.ActiveSheet.ActiveRowIndex, Me.ActiveSheet.ActiveColumnIndex)
        '        NewFp_EnterCell(Nothing, Ee)   '//이후에 엔터셀이 발생하지않으므로 발생시켜준다.

    End Sub

    ''' <summary>
    ''' 커서를 이전셀로 이동
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub APrev_Cell()
        If Me.ActiveSheet.ActiveRowIndex <> 0 Then '//첫줄이 아니면
            If Me.ActiveSheet.ActiveColumnIndex = 0 Then '/첫열이면 이전줄 첨으로 이동
                'SendKeys.Send("{TAB}")
                Me.ActiveSheet.ActiveRowIndex -= 1
                Me.ActiveSheet.ActiveColumnIndex = V_FIRSTINDEX '//첫인덱스로 옴긴다.기본값은 0이다.
                'Me.ActiveSheet.SetActiveCell(Me.ActiveSheet.ActiveRowIndex + 1, V_FIRSTINDEX)

            Else
                'SendKeys.Send("{TAB}")
                'Me.ActiveSheet.SetActiveCell(Me.ActiveSheet.ActiveRowIndex, Me.ActiveSheet.ActiveColumnIndex + 1)
                'Me.ActiveSheet.IsSelected(Me.ActiveSheet.ActiveRowIndex, Me.ActiveSheet.ActiveColumnIndex + 1)
                'ME.ActiveSheet.SEL
                Me.ActiveSheet.ActiveColumnIndex -= 1
            End If
        Else
            If Me.ActiveSheet.ActiveColumnIndex <> 0 Then '/첫열이 아니면
                'Me.ActiveSheet.ActiveRowIndex += 1
                Me.ActiveSheet.ActiveColumnIndex -= 1 '//첫인덱스로 옴긴다.기본값은 0이다.
            End If
        End If
    End Sub

    ''' <summary>
    ''' 커서를 다음줄로 이동
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ANEXT_ROW()
        If Me.ActiveSheet.ActiveRowIndex <> Me.ActiveSheet.RowCount - 1 Then '//마지막줄이 아니면
            Me.ActiveSheet.ActiveRowIndex += 1
            Me.ActiveSheet.ActiveColumnIndex = V_FIRSTINDEX '//첫인덱스로 옴긴다.기본값은 0이다.        
        End If
        Dim Ee As New FarPoint.Win.Spread.EnterCellEventArgs(Nothing, Me.ActiveSheet.ActiveRowIndex, Me.ActiveSheet.ActiveColumnIndex)
        NewFp_EnterCell(Nothing, Ee)   '//이후에 엔터셀이 발생하지않으므로 발생시켜준다.

    End Sub

    ''' <summary>
    ''' 커서를 이전줄로 이동
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub APrev_ROW()
        If Me.ActiveSheet.ActiveRowIndex <> 0 Then '//첫줄이 아니면
            Me.ActiveSheet.ActiveRowIndex -= 1
            Me.ActiveSheet.ActiveColumnIndex = V_FIRSTINDEX '//첫인덱스로 옴긴다.기본값은 0이다.        
        End If
    End Sub

    ''' <summary>
    ''' 선택줄번호에의하거나 입력한 열번호에 True 값을 전달합니다.(체크박스 체크용도)
    ''' </summary>
    ''' <param name="Columnindex"></param>
    ''' <remarks></remarks>
    Public Sub ASelect(Optional ByVal Columnindex As Int16 = -1)
        Dim sheet As FarPoint.Win.Spread.SheetView = Me.ActiveSheet
        If Columnindex = -1 AndAlso Me.ACheckBox_ColIndex <> -1 Then Columnindex = Me.ACheckBox_ColIndex '//지정된열제목이 잇는지
        For i As Integer = 0 To sheet.RowCount - 1
            sheet.Cells(i, Columnindex).Value = True
        Next
    End Sub

    ''' <summary>
    ''' 선택줄번호에의하거나 입력된 열번호에 FALSE 값을 전달합니다..(체크박스 해제용도)
    ''' </summary>
    ''' <param name="index"></param>
    ''' <remarks></remarks>
    Public Sub AUnselect(Optional ByVal index As Int16 = -1)
        Dim sheet As FarPoint.Win.Spread.SheetView = Me.ActiveSheet
        If index = -1 AndAlso Me.ACheckBox_ColIndex <> -1 Then index = Me.ACheckBox_ColIndex '//지정된열제목이 잇는지
        For i As Integer = 0 To sheet.RowCount - 1
            sheet.Cells(i, index).Value = False
        Next
    End Sub

    ''' <summary>
    ''' checkbox_colindex에의하거나 입력된 열번호를 가지고 선택반전 시킵니다.(체크박스 반전)
    ''' </summary>
    ''' <param name="index"></param>
    ''' <remarks></remarks>
    Public Sub AReverse(Optional ByVal index As Int16 = -1)
        Dim sheet As FarPoint.Win.Spread.SheetView = Me.ActiveSheet
        If index = -1 AndAlso Me.ACheckBox_ColIndex <> -1 Then index = ACheckBox_ColIndex '//지정된열제목이 잇는지
        For i As Integer = 0 To sheet.RowCount - 1
            sheet.Cells(i, index).Value = IIf(sheet.Cells(i, index).Value = True, False, True)
        Next
    End Sub


    ''' <summary>
    ''' 입력된 줄번호와 태그=데이터필드 가 일치하는 셀을 반환합니다.
    ''' </summary>
    ''' <param name="index"></param>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Cells(ByVal index As Integer, ByVal Tag As Object, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex

        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns

            If SC.DataField.ToUpper = Tag.ToString.ToUpper Then
                RetVal = Me.Sheets(Sheetindex).Cells(index, SC.Index)
                Exit For
            End If
        Next
        If RetVal Is Nothing Then
            MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function
    ''' <summary>
    ''' 현재선택된 줄의 열번호에해당하는 셀을 반환합니다.
    ''' </summary>
    ''' <param name="Columnindex"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Cells(ByVal Columnindex As Integer, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex
        Return Me.Sheets(Sheetindex).Cells(Me.ActiveSheet.ActiveRowIndex, Columnindex)
        Return RetVal
    End Function
    ''' <summary>
    ''' 현재선택된 셀을 반환합니다
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Cells() As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        Return Me.ActiveSheet.Cells(Me.ActiveRowindex, Me.ActiveColumnindex)
        Return RetVal
    End Function


    ''' <summary>
    ''' 전줄의 현재열위치 셀을 반환
    ''' </summary>
    ''' <param name="FirstrowValueisNothing"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CellsPR(Optional ByVal FirstrowValueisNothing As Boolean = False) As FarPoint.Win.Spread.Cell
        If FirstrowValueisNothing AndAlso Me.ActiveRowindex = 0 Then Return Nothing

        If Me.ActiveRowindex = 0 Then
            If FirstrowValueisNothing Then
                Return Nothing
            Else
                Return Me.ActiveSheet.ActiveCell
            End If
        Else
            Return Me.ActiveSheet.Cells(Me.ActiveRowindex - 1, Me.ActiveColumnindex)
        End If
    End Function
    ''' <summary>
    ''' 앞셀을 반환
    ''' </summary>
    ''' <param name="FirstColValueisNothing"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CellsPC(Optional ByVal FirstColValueisNothing As Boolean = False) As FarPoint.Win.Spread.Cell
        If FirstColValueisNothing AndAlso Me.ActiveColumnindex = 0 Then Return Nothing

        If Me.ActiveColumnindex = 0 Then
            If FirstColValueisNothing Then
                Return Nothing
            Else
                Return Me.ActiveSheet.ActiveCell
            End If
        Else
            Return Me.ActiveSheet.Cells(Me.ActiveRowindex, Me.ActiveColumnindex - 1)
        End If
    End Function
    ''' <summary>
    ''' 입력된 태그와 데이터필드가 일치하는 셀을 반환합니다.(줄번호는 현재줄)
    ''' </summary>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Cells(ByVal Tag As Object, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex

        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns

            If SC.DataField.ToUpper = Tag.ToString.ToUpper Then
                RetVal = Me.Sheets(Sheetindex).Cells(Me.ActiveRowindex, SC.Index)
                Exit For
            End If
        Next
        If RetVal Is Nothing Then
            MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function

    ''' <summary>
    ''' 입력된 태그와 데이터필드가 일치하는 셀을 반환합니다.(줄번호는 전줄)
    ''' </summary>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CellsR(ByVal Tag As Object, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        Dim Rindex As Integer = Me.ActiveSheet.ActiveRowIndex : If Rindex > 0 Then Rindex -= 1

        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex

        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns

            If SC.DataField.ToUpper = Tag.ToString.ToUpper Then
                RetVal = Me.Sheets(Sheetindex).Cells(Rindex, SC.Index)
                Exit For
            End If
        Next
        If RetVal Is Nothing Then
            MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function

    ''' <summary>
    '''  입력된태그(태그는 레이블명)와 일치하는 셀을 반환합니다.(줄번호는 현재줄)
    ''' </summary>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Cells2(ByVal Tag As String, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex
        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns
            If SC.Label.ToUpper = Tag.ToString.ToUpper Then
                RetVal = Me.Sheets(Sheetindex).Cells(Me.ActiveRowindex, SC.Index)
                Exit For
            End If
        Next
        If RetVal Is Nothing Then
            MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function


    ''' <summary>
    '''  입력된태그(태그는 레이블명)와 일치하는 열을 반환합니다.(줄번호는 현재줄)
    ''' </summary>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Column2(ByVal Tag As String, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Column
        Dim RetVal As FarPoint.Win.Spread.Column = Nothing
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex
        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns
            If SC.Label.ToUpper = Tag.ToString.ToUpper Then
                Return SC
            End If
        Next
        MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function column2")
        Return Nothing
    End Function


    ''' <summary>
    ''' 필드레이블과 일치하는 열의 위치를 반환합니다.
    ''' </summary>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ColIndex2(ByVal Tag As String, Optional ByVal Sheetindex As Integer = -1) As Integer
        Dim RetVal As Integer = -1
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex
        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns
            If SC.Label.ToUpper = Tag.ToString.ToUpper Then
                RetVal = SC.Index
                Exit For
            End If
        Next
        If RetVal = -1 Then
            MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function

    ''' <summary>
    ''' 열의 데이터필드와 일치하는열 번호를 반환
    ''' </summary>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ColIndex(ByVal Tag As String, Optional ByVal Sheetindex As Integer = -1) As Integer
        Dim RetVal As Integer = -1
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex
        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns
            If SC.DataField.ToUpper = Tag.ToString.ToUpper Then
                RetVal = SC.Index
                Exit For
            End If
        Next
        If RetVal = -1 Then
            MsgBox("Can't Find column [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function

    ''' <summary>
    ''' 입력된태그(레이블명)와 일치하는 셀을 반환합니다.
    ''' </summary>
    ''' <param name="RowIndex"></param>
    ''' <param name="Tag"></param>
    ''' <param name="Sheetindex"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Cells2(ByVal RowIndex As Integer, ByVal Tag As String, Optional ByVal Sheetindex As Integer = -1) As FarPoint.Win.Spread.Cell
        Dim RetVal As FarPoint.Win.Spread.Cell = Nothing
        If Sheetindex = -1 Then Sheetindex = Me.ActiveSheetIndex
        For Each SC As FarPoint.Win.Spread.Column In Me.Sheets(Sheetindex).Columns
            If SC.Label.ToUpper = Tag.ToString.ToUpper Then
                RetVal = Me.Sheets(Sheetindex).Cells(RowIndex, SC.Index)
                Exit For
            End If
        Next
        If RetVal Is Nothing Then
            MsgBox("Can't Find column Label [" & Tag.ToString & "]", MsgBoxStyle.Critical, "Farpoint function Cells")
        End If
        Return RetVal
    End Function


    ''' <summary>
    ''' 전줄을 반환합니다
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetProw() As FarPoint.Win.Spread.Row
        If Me.ActiveSheet.ActiveRowIndex = 0 Then Return Me.ActiveSheet.ActiveRow
        Return Me.ActiveSheet.Rows(Me.ActiveSheet.ActiveRowIndex - 1)
    End Function

    ''' <summary>
    ''' 활성화된 열제목줄을 반환합니다.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActiveColumn() As FarPoint.Win.Spread.Column
        Return Me.ActiveSheet.Columns(Me.ActiveColumnindex)
    End Function

    ''' <summary>
    ''' 활성화된 줄번호를 반환
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActiveRowindex() As Integer
        Return Me.ActiveSheet.ActiveRowIndex
    End Function
    ''' <summary>
    ''' 활성화된 열버호를 반환
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ActiveColumnindex() As Integer
        Return Me.ActiveSheet.ActiveColumnIndex
    End Function

#Region "설정저장부분"


    Public Sub AViewSetting_Load(ByVal 전줄값복사 As String, ByVal 한글필드 As String, ByVal 다음줄열이름 As String, Optional ByVal Tag As String = "", Optional ByVal FN As String = "")
        '//파라미터는 기본값이다 ini파일에 존재하지않았을경우 사용한다.
        Dim File As New System.IO.FileInfo(My.Application.Info.DirectoryPath & "\" & FN & "spread.INI")
        Dim a As New MyINI(File.FullName)

        If a.Exist = False Then Me.AViewSetting_Save(전줄값복사, 한글필드, 다음줄열이름, Tag, FN)

        Dim 전줄, 한글, 다음줄 As String
        전줄 = a.Read(Me.Parent.Name & "-" & (Me.Name & Tag), "prerowcopy", 전줄값복사)
        한글 = a.Read(Me.Parent.Name & "-" & (Me.Name & Tag), "hangulfield", 한글필드)
        다음줄 = a.Read(Me.Parent.Name & "-" & (Me.Name & Tag), "nextcolumn", 다음줄열이름)

        Me.전줄값복사 = 전줄.Split(",")
        Me.한글필드 = 한글.Split(",")
        Me.다음줄필드명 = 다음줄

    End Sub
    Public Sub AViewSetting_Save(ByVal 전줄값복사 As String, ByVal 한글필드 As String, ByVal 다음줄열이름 As String, Optional ByVal Tag As String = "", Optional ByVal FN As String = "")
        '//파라미터는 기본값이다 ini파일에 존재하지않았을경우 사용한다.
        Dim File As New System.IO.FileInfo(My.Application.Info.DirectoryPath & "\" & FN & "spread.INI")
        Dim a As New MyINI(File.FullName)
        If a.Exist = False Then a.Create()

        a.Write(Me.Parent.Name & "-" & (Me.Name & Tag), "prerowcopy", 전줄값복사)
        a.Write(Me.Parent.Name & "-" & (Me.Name & Tag), "hangulfield", 한글필드)
        a.Write(Me.Parent.Name & "-" & (Me.Name & Tag), "nextcolumn", 다음줄열이름)

    End Sub

    ''' <summary>
    ''' 뷰의 열너비,열이름(옵션),줌팩터등을 저장합니다.
    ''' </summary>
    ''' <param name="ColName"></param>
    ''' <remarks></remarks>
    Public Sub ASetting_Save(Optional ByVal ColName As Boolean = True, Optional ByVal Tag As String = "", Optional ByVal FN As String = "")
        ColSize_Save(Tag, FN)
        If ColName Then ColName_Save(Tag, FN)
        CurrentState_Save(Tag, FN)
        AZOOM_Save(Tag, FN)
        'MsgBox("뷰의 상태가 저장되었습니다", MsgBoxStyle.Information, "확인")
    End Sub
    ''' <summary>
    ''' 뷰의 열너비,열이름(옵션),줌팩터등을 불러옵니다
    ''' </summary>
    ''' <param name="ColName"></param>
    ''' <remarks></remarks>
    Public Sub ASetting_Load(Optional ByVal ColName As Boolean = True, Optional ByVal Tag As String = "", Optional ByVal FN As String = "")
        ColSize_Load(Tag, FN)
        If ColName Then ColName_Load(Tag, FN)
        CurrentState_Load(Tag, FN)
        AZOOM_LOAD(Tag, FN)
    End Sub
    ''' <summary>
    ''' 현재 열너비를 Spread.ini 파일에 저장합니다.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AZOOM_Save(ByVal tag As String, ByVal fn As String)
        Dim File As New System.IO.FileInfo(My.Application.Info.DirectoryPath & "\" & fn & "spread.INI")
        If System.IO.Directory.Exists(File.DirectoryName) = False Then System.IO.Directory.CreateDirectory(File.DirectoryName)
        Dim a As New MyINI(File.FullName)
        a.Write(Me.Parent.Name & "-" & (Me.Name & tag), "ZOOM", Me.ActiveSheet.ZoomFactor)

    End Sub
    ''' <summary>
    ''' 현재 열너비를 Spread.ini 파일로 부터 불러옵니다.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AZOOM_LOAD(ByVal tag As String, ByVal fn As String)
        Dim FILEname As String = My.Application.Info.DirectoryPath & "\" & fn & "spread.INI"
        If Not System.IO.File.Exists(FILEname) Then
            MsgBox("열너비 파일이 존재하지 않습니다", MsgBoxStyle.Critical, "열너비설정-오류")
            ColSize_Save(tag, fn)
            Return
        End If
        'MsgBox("PARENT" & Me.Parent.Name.ToString & "/" & Me.Parent.Text)
        Dim a As New MyINI(FILEname)
        Me.ActiveSheet.ZoomFactor = a.Read(Me.Parent.Name & "-" & (Me.Name & tag), "ZOOM", 1)



    End Sub
    ''' <summary>
    ''' 현재 열너비를 Spread.ini 파일에 저장합니다.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ColSize_Save(ByVal tag As String, ByVal fn As String)
        Dim File As New System.IO.FileInfo(My.Application.Info.DirectoryPath & "\" & fn & "spread.INI")
        If System.IO.Directory.Exists(File.DirectoryName) = False Then System.IO.Directory.CreateDirectory(File.DirectoryName)
        Dim a As New MyINI(File.FullName)
        For Each z As FarPoint.Win.Spread.Column In Me.ActiveSheet.Columns
            a.Write(Me.Parent.Name & "-" & (Me.Name & tag), "COLSIZE" & z.Index.ToString, z.Width)
        Next
    End Sub

    ''' <summary>
    ''' 현재 열너비를 Spread.ini 파일로 부터 불러옵니다.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ColSize_Load(ByVal tag As String, ByVal fn As String)
        Dim FILEname As String = My.Application.Info.DirectoryPath & "\" & fn & "spread.INI"
        If Not System.IO.File.Exists(FILEname) Then
            MsgBox("열너비 파일이 존재하지 않습니다", MsgBoxStyle.Critical, "열너비설정-오류")
            ColSize_Save(tag, fn)
            Return
        End If
        'MsgBox("PARENT" & Me.Parent.Name.ToString & "/" & Me.Parent.Text)
        Dim a As New MyINI(FILEname)
        For Each col As FarPoint.Win.Spread.Column In Me.ActiveSheet.Columns
            'MsgBox(COL.Index)
            'a.Write(Me.Parent.Name, "COLSIZE" & COL.Index.ToString, File, COL.Width)
            Try
                col.Width = a.Read(Me.Parent.Name & "-" & (Me.Name & tag), "COLSIZE" & col.Index.ToString)
            Catch ex As Exception   '//없을경우에는 에러를 내므로 그냥 나간다

            End Try
        Next
    End Sub
    Public Sub ColName_Load(ByVal tag As String, ByVal fn As String)
        Dim FILEname As String = My.Application.Info.DirectoryPath & "\" & fn & "spread.INI"

        If Not System.IO.File.Exists(FILEname) Then
            MsgBox("열너비 파일이 존재하지 않습니다", MsgBoxStyle.Critical, "열너비설정-오류")
            ColSize_Save(tag, fn)
            Return
        End If
        'MsgBox("PARENT" & Me.Parent.Name.ToString & "/" & Me.Parent.Text)
        Dim a As New MyINI(FILEname)
        For Each col As FarPoint.Win.Spread.Column In Me.ActiveSheet.Columns
            'MsgBox(COL.Index)
            'a.Write(Me.Parent.Name, "COLSIZE" & COL.Index.ToString, File, COL.Width)
            Try
                col.Label = a.Read(Me.Parent.Name & "-" & Me.Name & tag, "COLNAME" & col.Index.ToString).ToString.Trim(Chr(0))
            Catch ex As Exception   '//없을경우에는 에러를 내므로 그냥 나간다
            End Try
        Next
    End Sub
    Public Sub ColName_Save(ByVal tag As String, ByVal fn As String)
        Dim File As New System.IO.FileInfo(My.Application.Info.DirectoryPath & "\" & fn & "spread.INI")
        If System.IO.Directory.Exists(File.DirectoryName) = False Then System.IO.Directory.CreateDirectory(File.DirectoryName)
        Dim a As New MyINI(File.FullName)
        For Each z As FarPoint.Win.Spread.Column In Me.ActiveSheet.Columns
            a.Write(Me.Parent.Name & "-" & Me.Name & tag, "COLNAME" & z.Index.ToString, z.Label)
        Next
    End Sub

    ''' <summary>
    ''' [보충요망] :줄높이를 저장
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub CurrentState_Save(ByVal tag As String, ByVal fn As String)
        Dim File As New System.IO.FileInfo(My.Application.Info.DirectoryPath & "\" & fn & "spread.INI")
        If System.IO.Directory.Exists(File.DirectoryName) = False Then System.IO.Directory.CreateDirectory(File.DirectoryName)
        Dim a As New MyINI(File.FullName)
        a.Write(Me.Parent.Name & "-" & Me.Name & tag, "RowHeight", Me.ActiveSheet.Rows.Default.Height)
    End Sub

    ''' <summary>
    ''' [보충요망] :줄높이를 불러온다.(spre.ini)
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub CurrentState_Load(ByVal tag As String, ByVal fn As String)
        Dim FILEname As String = My.Application.Info.DirectoryPath & "\" & fn & "spread.INI"
        If Not System.IO.File.Exists(FILEname) Then
            MsgBox("열너비 파일이 존재하지 않습니다", MsgBoxStyle.Critical, "열너비설정-오류")
            CurrentState_Save(tag, fn)
            Return
        End If
        Dim a As New MyINI(My.Application.Info.DirectoryPath & "\" & fn & "spread.INI")
        Me.ActiveSheet.Rows.Default.Height = a.Read(Me.Parent.Name & "-" & Me.Name & tag, "RowHeight", 20)
    End Sub

#End Region
    Private Sub Delete_itm(Optional ByVal rowindex As Integer = -1, Optional ByVal prompt As Boolean = True)
        Dim Commit As Boolean = True
        Dim A As New System.Text.StringBuilder("경고 : 데이터 삭제를 선택했습니다")
        A.AppendLine()
        A.AppendLine("현재 선택된 줄이 삭제됩니다")
        A.AppendLine("계속하시겠습니까?")
        If prompt Then
            If MsgBox(A.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkCancel, "선택줄 삭제") <> MsgBoxResult.Ok Then Commit = False
        End If
        If Not Commit Then Return '//명령프롬프트에서 취소를 선택햇을시에는  빠져나간다.
        Me.ActiveSheet.ActiveRow.Remove()
    End Sub

    Private Sub NewFp_EditModeOff(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.EditModeOff
        RaiseEvent Arin_Before_EditModeOff(sender, e)   '//원래뷰가 after 발생이므로 before 발생용 이벤트하나 맹글어준다.
        RaiseEvent Arin_LovCodeEntry(sender, e)   '//빠져나오는순간의 Lov코드용이다.

        If Not Me.v_ACellposLabel Is Nothing Then
            Me.v_ACellposLabel.ForeColor = Color.Black
        End If
        '//빠져나올때 이 셀번호가 종료열번호라면 다음줄로 넘긴다
        If Me.V_enterToTab Then
            If (Me.ANextRow_ColIndex = Me.ActiveSheet.ActiveColumnIndex) OrElse (Me.ActiveSheet.ActiveColumnIndex = (Me.ActiveSheet.ColumnCount - 1)) Then '//다음줄로가아햘 경우라면
                RaiseEvent Arin_AddLog(Me, "editmode off  and next_row")
                Me.ANEXT_ROW()
            Else
                RaiseEvent Arin_AddLog(Me, "editmode off nextcell")
                Me.ANext_Cell()
            End If
        End If

    End Sub

    Private Sub NewFp_EditModeOn(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.EditModeOn
        RaiseEvent Arin_AddLog(Me, "editmode on")
        If Not Me.v_ACellposLabel Is Nothing Then
            Me.v_ACellposLabel.ForeColor = Color.Red
        End If
    End Sub

    ''' <summary>
    ''' 셀에 진입햇을시의 프로시져.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub NewFp_EnterCell(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.EnterCellEventArgs) Handles Me.EnterCell
        If Not Me.v_ACellposLabel Is Nothing Then
            Me.v_ACellposLabel.Text = "[" & Me.ActiveColumn.Label & ":" & Me.ActiveSheet.ActiveRowIndex + 1 & ":" & Me.ActiveSheet.ActiveColumnIndex & "/" & Me.ActiveSheet.RowCount & "]"
        End If
        ' Me.Text = Me.view1.한글필드.GetUpperBound(0) & "/" & Array.IndexOf(Me.view1.한글필드, .ActiveColumn.Label)
        If Not Me.한글필드 Is Nothing AndAlso Me.한글필드.GetUpperBound(0) >= 0 Then
            If Array.IndexOf(Me.한글필드, Me.ActiveColumn.Label) >= 0 Then
                Me.ImeMode = Windows.Forms.ImeMode.Hangul
            Else
                Me.ImeMode = Windows.Forms.ImeMode.Alpha
            End If
        End If
    End Sub

    Private Sub NewFp_ImeModeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ImeModeChanged
        If Not Me.v_ACellImeLabel Is Nothing Then
            If Me.ImeMode = Windows.Forms.ImeMode.Hangul Then
                Me.v_ACellImeLabel.Text = ("[한글]")
                Me.v_ACellImeLabel.ForeColor = Color.Blue
            Else
                Me.v_ACellImeLabel.Text = ("[일반]")
                Me.v_ACellImeLabel.ForeColor = Color.Black
            End If
        End If
    End Sub


    ''' <summary>
    ''' 뷰에서 키보드가 눌렷을대의 반응
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub CustFP_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        RaiseEvent Arin_AddLog(Me, "keydown 발생 코드=" & e.KeyCode & "현재줄번호 : " & _
    Me.ActiveSheet.ActiveRowIndex & " 현재열번호:" & Me.ActiveSheet.ActiveColumnIndex & " 다음줄로이동할열번호:" & Me.ANextRow_ColIndex)

        RaiseEvent Arin_Before_KeyDown(sender, e) : RaiseEvent Arin_AddLog(Me, "Before Keydown 이벤트를 발생시켰습니다.")

        Select Case e.KeyCode
            Case Keys.Enter
                e.SuppressKeyPress = False
                e.Handled = True

                If e.Control Then '//윗줄값을복사
                    RaiseEvent Arin_AddLog(Me, "keydown control 에의해 윗줄 복사")
                    Me.Cells.Value = Me.CellsPR.Value
                    '//복사하고 그자리에 멈춘다.
                Else

                    '//빈줄일때 상위값 복사하는루틴이 원ㄹ ㅐview 에 잇었으나 해당 keydown 이벤트가 이곳보다 나중에 일어나기떄문에
                    '//사용할수가없게되었다.
                    If Me.V_enterToTab Then
                        If Me.ActiveSheet.ActiveRowIndex = Me.ActiveSheet.RowCount - 1 Then '//마지막줄일경우
                            If (Me.ANextRow_ColIndex = Me.ActiveSheet.ActiveColumnIndex) OrElse (Me.ActiveSheet.ActiveColumnIndex = (Me.ActiveSheet.ColumnCount - 1)) Then '//다음줄로가아햘 경우라면
                                RaiseEvent Arin_AddLog(Me, "keydown 마지막줄이며 한줄생성해야함 " & Me.ANextRow_ColIndex & "/" & Me.ActiveSheet.ActiveColumnIndex)
                                If Not Me.v_AAutoAddrowInLast Is Nothing Then
                                    Me.v_AAutoAddrowInLast.PerformClick()    '//한줄추가
                                    Me.ActiveSheet.ActiveColumnIndex = Me.V_FIRSTINDEX
                                    NewFp_EnterCell(sender, Nothing)
                                End If
                            Else   '//마지막줄이고 다음줄이아니면 다음셀로이동
                                RaiseEvent Arin_AddLog(Me, "keydown 마지막줄이나 다음셀로 감")
                                Me.ANext_Cell() '//신규추가줄

                            End If
                        Else   '//마지막줄이아니고 마지막열이면 다음줄로
                            'MsgBox(Me.ANextRow_ColIndex & "/" & Me.ActiveSheet.ActiveColumnIndex)
                            If (Me.ANextRow_ColIndex = Me.ActiveSheet.ActiveColumnIndex) OrElse (Me.ActiveSheet.ActiveColumnIndex = (Me.ActiveSheet.ColumnCount - 1)) Then '//다음줄로가아햘 경우라면
                                RaiseEvent Arin_AddLog(Me, "keydown 마지막줄이아니며 다음줄로" & Me.ANextRow_ColIndex & "/" & Me.ActiveSheet.ActiveColumnIndex)
                                Me.ANEXT_ROW()
                            Else
                                RaiseEvent Arin_AddLog(Me, "keydown 마지막줄이아니며 다음셀로")
                                Me.ANext_Cell()
                            End If
                        End If
                    End If

                End If

            Case Keys.Delete
                If e.Shift Then '//쉬프트가 눌러져잇을경우
                    If Me.V_DeleteKey Then Delete_itm(, True)
                    e.Handled = True
                Else
                    If Me.V_CurrentDel Then
                        If Not Me.ActiveSheet.ActiveCell.Locked AndAlso Not Me.ActiveSheet.ActiveColumn.Locked Then
                            Me.ActiveSheet.ActiveCell.ResetValue()
                        Else
                            Me.Disp_Msg("현재 셀은 잠겨있으므로 값을 삭제할 수 없습니다")
                        End If
                        'Me.OnEditModeOff(Nothing)
                        e.Handled = True
                    End If
                End If

            Case Keys.Space  '//편집모드
                If Me.V_SpaceEdit Then EditMode = True
                e.Handled = True
            Case Keys.F1
            Case Keys.F2
            Case Keys.F3
            Case Keys.F4
            Case Keys.F5 '//Lov용이다. 위치에서 누르는 F5키는 모두검색하는 lOv로 변경한다.
                RaiseEvent Arin_LovCodeEntry(sender, Nothing)
            Case Keys.F6
            Case Keys.F7
            Case Keys.F8
            Case Keys.F9
            Case Keys.F10
            Case Keys.F11
            Case Keys.F12
            Case 18   '//왼쪽ALT
                e.SuppressKeyPress = False
                e.Handled = True
            Case Else '//그외다른게입력되어있을경우에는 editmode 에 들어가게되므로 한글처리를 위해 바로 에디트모드로 들어오게한다.

                If e.KeyCode >= Keys.NumPad0 AndAlso e.KeyCode <= Keys.NumPad9 Then
                    '//우측숫자패트 
                ElseIf e.KeyCode >= Keys.D0 AndAlso e.KeyCode <= Keys.D9 Then
                    '//일반숫자패드
                Else
                    If Not e.Alt AndAlso Not e.Control AndAlso Me.ImeMode = Windows.Forms.ImeMode.Hangul Then
                        EditMode = True
                    End If
                End If

        End Select
    End Sub

    ''' <summary>
    ''' 뷰의 줄 높이 변경되었을때의 반응
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub CustFP_RowHeightChanged(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.RowHeightChangedEventArgs) Handles Me.RowHeightChanged
        If Me.V_sameRHeight Then
            Dim Row As FarPoint.Win.Spread.RowHeightChangeExtents = e.RowList(0)
            Me.ActiveSheet.Rows.Default.Height = Me.ActiveSheet.Rows(Row.FirstRow).Height
        End If
    End Sub

    Public Sub Excel_Save(ByVal Filename As String, Optional ByVal INitdir As String = vbNullString, Optional ByVal Asfilter As Boolean = False)
        If Me.ActiveSheet.Rows.Count <= 0 Then
            MsgBox("내보내기할 목록이 존재하지 않습니다", MsgBoxStyle.Critical, "확인")
            Exit Sub
        End If
        Try
            Dim A As New SaveFileDialog
            A.InitialDirectory = IIf(INitdir = vbNullString, My.Application.Info.DirectoryPath, INitdir)
            A.Filter = "엑셀 워크시트파일|*.XLS"
            A.FileName = Filename
            If A.ShowDialog = Windows.Forms.DialogResult.OK Then
                ' Me.prb1.Style = ProgressBarStyle.Marquee
                If Not Asfilter Then
                    Me.SaveExcel(A.FileName, FarPoint.Excel.ExcelSaveFlags.SaveBothCustomRowAndColumnHeaders)
                Else
                    Me.SaveExcel(A.FileName, FarPoint.Excel.ExcelSaveFlags.SaveAsFiltered)
                End If
            End If

        Catch ex As Exception
            MsgBox("내보내기실패" & vbCrLf & ex.ToString, MsgBoxStyle.Critical, "확인")

        End Try

    End Sub
    ''' <summary>
    ''' 싱글로우형식을때 표시하고자하는 DatarowView 를 보내주면 셀의 TAG를 맞춰서 표시합니다.
    ''' </summary>
    ''' <param name="Drv"></param>
    ''' <remarks></remarks>
    Public Sub ASingleRow_Viewer(ByVal Drv As DataRowView, ByVal StartRange As Point, ByVal EndRange As Point)
        For i As Integer = StartRange.Y To EndRange.Y '//범위행
            For j As Integer = StartRange.X To EndRange.X    '//범위열
                If Not Me.ActiveSheet.Cells(i, j).Tag Is Nothing Then
                    Me.ActiveSheet.Cells(i, j).Text = Drv(Me.ActiveSheet.Cells(i, j).Tag.ToString)
                End If
            Next
        Next
    End Sub
    ''' <summary>
    ''' 싱글로우형식을때 표시하고자하는 DatarowView 를 보내주면 셀의 TAG를 맞춰서 표시합니다.
    ''' </summary>
    ''' <param name="Drv"></param>
    ''' <remarks></remarks>
    Public Sub ASingleRow_Viewer(ByVal Drv As DataRowView)
        For Each RW As FarPoint.Win.Spread.Row In Me.ActiveSheet.Rows
            For Each CL As FarPoint.Win.Spread.Column In Me.ActiveSheet.Columns
                If Not Me.ActiveSheet.Cells(RW.Index, CL.Index).Tag Is Nothing Then
                    If Drv(Me.ActiveSheet.Cells(RW.Index, CL.Index).Tag.ToString) Is DBNull.Value Then
                        Me.ActiveSheet.Cells(RW.Index, CL.Index).Value = ""
                    Else
                        Me.ActiveSheet.Cells(RW.Index, CL.Index).Value = Drv(Me.ActiveSheet.Cells(RW.Index, CL.Index).Tag.ToString)
                    End If

                End If
            Next
        Next
    End Sub

    ''' <summary>
    ''' 싱글로우형식을 사용할때 스프레드값을 데이터테이블에 보낸다.
    ''' </summary>
    ''' <param name="Drv"></param>
    ''' <remarks></remarks>
    Public Sub ASingleRow_Writer(ByRef Drv As DataRowView)
        If Not Me.ActiveSheet.ActiveCell.Tag Is Nothing Then
            'MsgBox(Me.ActiveSheet.ActiveCell.Text)
            Drv(Me.ActiveSheet.ActiveCell.Tag.ToString) = Me.ActiveSheet.ActiveCell.Value
        End If
    End Sub

    Public Sub New()

        ' 이 호출은 Windows Form 디자이너에 필요합니다.
        InitializeComponent()

        ' InitializeComponent() 호출 뒤에 초기화 코드를 추가하십시오.

    End Sub
End Class
