LboxGrid メソッド (2)


  EnterToTab




  

Private bEnterToTab As Boolean

' ******************************************************
' Enter To Tab プロパティ
' ******************************************************
<System.ComponentModel.Description("Enterキーの動作をTABキーと同じにする"), _
System.ComponentModel.Browsable(True), _
System.ComponentModel.DefaultValue(False)> _
Public Property isEnterToTab() As Boolean
	Get
		Return bEnterToTab
	End Get
	Set(ByVal value As Boolean)
		bEnterToTab = value
	End Set
End Property

' ******************************************************
' Enter To Tab メソッド
' ******************************************************
Public Sub EnterToTab(ByVal flg As Boolean)

	bEnterToTab = flg

End Sub

' ******************************************************
' Enterキーが押されると発生するイベント
' ******************************************************
Public Event EnterKey(ByVal e As lightbox.EnterKeyEventArgs)

' ******************************************************
' Enter To Tab の実際の処理
' ******************************************************
Protected Overrides Function ProcessDialogKey( _
  ByVal keyData As Keys) As Boolean
	If (keyData And Keys.KeyCode) = Keys.Enter Then
		' ******************************************************
		' EnterKeyイベントの処理
		' ******************************************************
		Dim e As New lightbox.EnterKeyEventArgs()
		e.EnterToTab = bEnterToTab
		e.Shift = ((Control.ModifierKeys And Keys.Shift) = Keys.Shift)
		e.Alt = ((Control.ModifierKeys And Keys.Alt) = Keys.Alt)
		e.Control = ((Control.ModifierKeys And Keys.Control) = Keys.Control)
		RaiseEvent EnterKey(e)

		If bEnterToTab Then
			Return Me.ProcessTabKey(keyData)
		End If
	End If
	Return MyBase.ProcessDialogKey(keyData)
End Function

Protected Overrides Function ProcessDataGridViewKey( _
  ByVal e As KeyEventArgs) As Boolean
	If e.KeyCode = Keys.Enter Then
		' ******************************************************
		' EnterKeyイベントの処理
		' ******************************************************
		Dim e2 As New lightbox.EnterKeyEventArgs()
		e2.EnterToTab = bEnterToTab
		e2.Shift = e.Shift
		e2.Alt = ((Control.ModifierKeys And Keys.Alt) = Keys.Alt)
		e2.Control = ((Control.ModifierKeys And Keys.Control) = Keys.Control)
		RaiseEvent EnterKey(e2)

		If bEnterToTab Then
			Return Me.ProcessTabKey(e.KeyCode)
		End If
	End If
	Return MyBase.ProcessDataGridViewKey(e)
End Function
  


↓参考
http://msdn.microsoft.com/ja-jp/library/system.windows.forms.datagridview.processdialogkey.aspx






  MoveRow




  

' ******************************************************
' 行移動
' nSourceIndex  の行を nIndex の行の前に移動する
' nIndexに -1 を指定すると、行の最後に移動
' ******************************************************
Public Sub MoveRow(ByVal nSourceIndex As Integer, ByVal nIndex As Integer)

	If nIndex = -1 Then
		nIndex = Me.GetRowCount()
	End If

	Me.Rows.InsertCopy(nSourceIndex, nIndex)

	Dim nTarget As Integer = 0
	If Me.nCurrentRow >= nIndex Then
		nTarget = nSourceIndex + 1
	Else
		nTarget = nSourceIndex
	End If

	Dim nCount As Integer = Me.GetColumnCount()
	Dim idx As Integer
	For idx = 0 To nCount - 1
		Me.Rows(nIndex).Cells(idx).Value = Me.Rows(nTarget).Cells(idx).Value
	Next
	Me.SetRowFlg(nIndex, Me.GetRowFlg(nTarget))

	Me.Rows.RemoveAt(nTarget)

End Sub

' ******************************************************
' 行移動
' nCurrentRow の行を nIndex の行の前に移動する
' nIndex に -1 を指定すると、行の最後に移動
' ******************************************************
Public Sub MoveRow(ByVal nIndex As Integer)

	Me.MoveRow(Me.nCurrentRow, nIndex)

End Sub
  

  LoadSqlMdb

↓使用方法
http://winofsql.jp/VA003334/dnettool080129154915.htm

  

' ******************************************************
' MDBロード
' ******************************************************
Public Function LoadSqlMdb(ByVal Query As String, _
Optional ByVal nMaxCount As Integer = 100) As Boolean

	LoadSqlMdb = True
	Me.DbError = ""

	' 接続文字列
	_ConnectString = _
	  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
	"Data Source=" & _DbServer & ";"

	' 接続オブジェクト
	Dim myCon As New OleDbConnection()
	myCon.ConnectionString = _ConnectString
	Try
		myCon.Open()
	Catch e As Exception
		DbError = e.Message
		LoadSqlMdb = False
		Exit Function
	End Try

	' コマンドブジェクト
	Dim myCommand As New OleDbCommand()
	myCommand.CommandText = Query
	myCommand.Connection = myCon

	' リーダ
	Dim myReader As OleDbDataReader
	myReader = myCommand.ExecuteReader()

	' 列数
	Dim nCols As Integer = myReader.FieldCount
	Dim idx As Integer
	Dim fldName As String
	Dim fldValue As String
	Dim fldType As System.Type

	' 列作成
	Me.Reset()
	For idx = 0 To nCols - 1
		fldName = myReader.GetName(idx)
		Me.AddColumn(fldName, fldName)
	Next

	Dim nRow As Integer = 0
	Do While myReader.Read()
		Me.AddRow()
		nRow = nRow + 1
		If nRow > nMaxCount Then
			Exit Do
		End If
		For idx = 0 To nCols - 1
			If Not myReader.IsDBNull(idx) Then
				fldType = myReader.GetFieldType(idx)
				If fldType.Name = "String" Then
					fldValue = myReader.GetValue(idx) + ""
					Me.SetColumnText(idx, fldValue)
				ElseIf fldType.Name = "Int32" Then
					fldValue = myReader.GetInt32(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				ElseIf fldType.Name = "DateTime" Then
					fldValue = myReader.GetDateTime(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				Else
					fldValue = myReader.GetValue(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				End If
			Else
				Me.SetColumnText(idx, "")
			End If
		Next
	Loop

	myReader.Close()
	myCon.Close()

End Function
  

  LoadSqlOdbc

↓使用方法
http://winofsql.jp/VA003334/dnettool080129154915.htm

  

' ******************************************************
' ODBCロード
' ******************************************************
Public Function LoadSqlOdbc(ByVal Query As String, _
Optional ByVal nMaxCount As Integer = 100) As Boolean

	LoadSqlOdbc = True
	Me.DbError = ""

	If _DbDriver = "" Then
		' 接続文字列
		_ConnectString = _
		  "DSN=" & _DbServer & ";"

		If _DbDatabase <> "" Then
			_ConnectString &= "DATABASE=" & _DbDatabase & ";"
		End If

		_ConnectString &= _
		  "UID=" & _DbUser & ";" + _
		  "PWD=" & _DbPass & ";"
	Else
		' 接続文字列
		_ConnectString = _
		  "Driver={" & _DbDriver & "};" + _
		  "SERVER=" & _DbServer & ";"

		If _DbDatabase <> "" Then
			_ConnectString &= "DATABASE=" & _DbDatabase & ";"
		End If

		_ConnectString &= _
		  "UID=" & _DbUser & ";" + _
		  "PWD=" & _DbPass & ";"
	End If


	' 接続オブジェクト
	Dim myCon As New OdbcConnection()
	myCon.ConnectionString = _ConnectString
	Try
		myCon.Open()
	Catch e As Exception
		DbError = e.Message
		LoadSqlOdbc = False
		Exit Function
	End Try

	' コマンドブジェクト
	Dim myCommand As New OdbcCommand()
	myCommand.CommandText = Query
	myCommand.Connection = myCon

	' リーダ
	Dim myReader As OdbcDataReader
	myReader = myCommand.ExecuteReader()

	' 列数
	Dim nCols As Integer = myReader.FieldCount
	Dim idx As Integer
	Dim fldName As String
	Dim fldValue As String
	Dim fldType As System.Type

	' 列作成
	Me.Reset()
	For idx = 0 To nCols - 1
		fldName = myReader.GetName(idx)
		Me.AddColumn(fldName, fldName)
	Next

	Dim nRow As Integer = 0
	Do While myReader.Read()
		Me.AddRow()
		nRow = nRow + 1
		If nRow > nMaxCount Then
			Exit Do
		End If
		For idx = 0 To nCols - 1
			If Not myReader.IsDBNull(idx) Then
				fldType = myReader.GetFieldType(idx)
				If fldType.Name = "String" Then
					fldValue = myReader.GetValue(idx) + ""
					Me.SetColumnText(idx, fldValue)
				ElseIf fldType.Name = "Int32" Then
					fldValue = myReader.GetInt32(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				ElseIf fldType.Name = "DateTime" Then
					fldValue = myReader.GetDateTime(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				Else
					fldValue = myReader.GetValue(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				End If
			Else
				Me.SetColumnText(idx, "")
			End If
		Next
	Loop

	myReader.Close()
	myCon.Close()

End Function
  

  LoadSqlServer

↓使用方法
http://winofsql.jp/VA003334/dnettool080129154915.htm

  

' ******************************************************
' SQLServer ロード
' ******************************************************
Public Function LoadSqlServer(ByVal Query As String, _
Optional ByVal nMaxCount As Integer = 100) As Boolean

	LoadSqlServer = True
	Me.DbError = ""

	' 接続文字列
	_ConnectString = _
	"Data Source=" & _DbServer & ";" + _
	"Initial Catalog=" & _DbDatabase & ";" + _
	"User ID=" & _DbUser & ";" + _
	"Password=" & _DbPass & ";"

	' 接続オブジェクト
	Dim myCon As New SqlConnection()
	myCon.ConnectionString = _ConnectString
	Try
		myCon.Open()
	Catch e As Exception
		DbError = e.Message
		LoadSqlServer = False
		Exit Function
	End Try

	' コマンドブジェクト
	Dim myCommand As New SqlCommand()
	myCommand.CommandText = Query
	myCommand.Connection = myCon

	' リーダ
	Dim myReader As SqlDataReader
	myReader = myCommand.ExecuteReader()

	' 列数
	Dim nCols As Integer = myReader.FieldCount
	Dim idx As Integer
	Dim fldName As String
	Dim fldValue As String
	Dim fldType As System.Type

	' 列作成
	Me.Reset()
	For idx = 0 To nCols - 1
		fldName = myReader.GetName(idx)
		Me.AddColumn(fldName, fldName)
	Next

	Dim nRow As Integer = 0
	Do While myReader.Read()
		Me.AddRow()
		nRow = nRow + 1
		If nRow > nMaxCount Then
			Exit Do
		End If
		For idx = 0 To nCols - 1
			If Not myReader.IsDBNull(idx) Then
				fldType = myReader.GetFieldType(idx)
				If fldType.Name = "String" Then
					fldValue = myReader.GetValue(idx) + ""
					Me.SetColumnText(idx, fldValue)
				ElseIf fldType.Name = "Int32" Then
					fldValue = myReader.GetInt32(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				ElseIf fldType.Name = "DateTime" Then
					fldValue = myReader.GetDateTime(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				Else
					fldValue = myReader.GetValue(idx).ToString() + ""
					Me.SetColumnText(idx, fldValue)
				End If
			Else
				Me.SetColumnText(idx, "")
			End If
		Next
	Loop

	myReader.Close()
	myCon.Close()

End Function
  

  文字列以外のCellアクセス

SetColumnValue は、Object 型をセットします
SetColumnTag も、Object 型をセットします

SET
  

Public Sub SetColumnValue(ByVal nRow As Integer, _
 ByVal strName As String, ByVal value As Object)

	Me.Rows(nRow).Cells(strName).Value = value

End Sub
Public Sub SetColumnValue(ByVal nRow As Integer, _
 ByVal nCol As Integer, ByVal value As Object)

	Me.Rows(nRow).Cells(nCol).Value = value

End Sub
Public Sub SetColumnValue(ByVal strName As String, ByVal value As Object)

	Me.Rows(nCurrentRow).Cells(strName).Value = value

End Sub
Public Sub SetColumnValue(ByVal nCol As Integer, ByVal value As Object)

	Me.Rows(nCurrentRow).Cells(nCol).Value = value

End Sub
Public Sub SetColumnTag(ByVal nRow As Integer, _
  ByVal strName As String, ByVal value As Object)

	Me.Rows(nRow).Cells(strName).Tag = value

End Sub
Public Sub SetColumnTag(ByVal nRow As Integer, _
 ByVal nCol As Integer, ByVal value As Object)

	Me.Rows(nRow).Cells(nCol).Tag = value

End Sub
Public Sub SetColumnTag(ByVal strName As String, ByVal value As Object)

	Me.Rows(nCurrentRow).Cells(strName).Tag = value

End Sub
Public Sub SetColumnTag(ByVal nCol As Integer, ByVal value As Object)

	Me.Rows(nCurrentRow).Cells(nCol).Tag = value

End Sub
  

GetColumnValue は、Object 型を取得します
GetColumnTag も、Object 型を取得します
GetColumnBoolean は、コードに意味を持たす為に、CheckBox 型のセルで使用すると良いでしょう
( GetColumnValue でも OK です )

GET
  

Public Function GetColumnTag(ByVal strName As String) As Object

	GetColumnTag = Me.Rows(nCurrentRow).Cells(strName).Tag

End Function
Public Function GetColumnTag(ByVal nCol As Integer) As Object

	GetColumnTag = Me.Rows(nCurrentRow).Cells(nCol).Tag

End Function
Public Function GetColumnTag(ByVal nRow As Integer, _
   ByVal strName As String) As Object

	GetColumnTag = Me.Rows(nRow).Cells(strName).Tag

End Function
Public Function GetColumnTag(ByVal nRow As Integer, _
   ByVal nCol As Integer) As Object

	GetColumnTag = Me.Rows(nRow).Cells(nCol).Tag

End Function
Public Function GetColumnValue(ByVal strName As String) As Object

	GetColumnValue = Me.Rows(nCurrentRow).Cells(strName).Value

End Function
Public Function GetColumnValue(ByVal nCol As Integer) As Object

	GetColumnValue = Me.Rows(nCurrentRow).Cells(nCol).Value

End Function
Public Function GetColumnValue(ByVal nRow As Integer, _
  ByVal strName As String) As Object

	GetColumnValue = Me.Rows(nRow).Cells(strName).Value

End Function
Public Function GetColumnValue(ByVal nRow As Integer, _
  ByVal nCol As Integer) As Object

	GetColumnValue = Me.Rows(nRow).Cells(nCol).Value

End Function
Public Function GetColumnBoolean(ByVal strName As String) As Boolean

	GetColumnBoolean = CType(Me.Rows(nCurrentRow).Cells(strName).Value, Boolean)

End Function
Public Function GetColumnBoolean(ByVal nCol As Integer) As Boolean

	GetColumnBoolean = CType(Me.Rows(nCurrentRow).Cells(nCol).Value, Boolean)

End Function
Public Function GetColumnBoolean(ByVal nRow As Integer, _
  ByVal strName As String) As Boolean

	GetColumnBoolean = CType(Me.Rows(nRow).Cells(strName).Value, Boolean)

End Function
Public Function GetColumnBoolean(ByVal nRow As Integer, _
  ByVal nCol As Integer) As Boolean

	GetColumnBoolean = CType(Me.Rows(nRow).Cells(nCol).Value, Boolean)

End Function
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[dnettool]
claudebot
24/04/16 18:01:27
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube