{"id":4023,"date":"2012-09-13T01:00:00","date_gmt":"2012-09-12T16:00:00","guid":{"rendered":"http:\/\/keuko.exp.jp\/diary\/?p=4023"},"modified":"2012-09-13T01:00:00","modified_gmt":"2012-09-12T16:00:00","slug":"datagridview%e3%81%ae%e3%82%ab%e3%83%bc%e3%82%bd%e3%83%ab%e5%88%b6%e5%be%a1","status":"publish","type":"post","link":"https:\/\/keuko.exp.jp\/diary\/?p=4023","title":{"rendered":"DataGridView\u306e\u30ab\u30fc\u30bd\u30eb\u5236\u5fa1"},"content":{"rendered":"<p>\u3048\u3048\u3068\u3001VB2010\u306eDataGridView\u3067\u77e2\u5370\u30ad\u30fc\u3068\u304bEnter\u30ad\u30fc\u3068\u304bTab\u30ad\u30fc\u3067\u30ab\u30fc\u30bd\u30eb\u79fb\u52d5\u3092\u3055\u305b\u305f\u3044\u306a\u30fc\u3068\u601d\u3063\u3066\u82e6\u6226\u3057\u305f\u306e\u3067\u30e1\u30e2\u3002<br \/>\n\u975e\u8868\u793a\u3084\u5165\u529b\u4e0d\u53ef\u306e\u30bb\u30eb\u3092\u98db\u3070\u3057\u3066\u79fb\u52d5\u3057\u307e\u3059\u3002\u7aef\u306e\u30bb\u30eb\u306e\u5834\u5408\u306f\u524d\u306e\u884c\u307e\u305f\u306f\u6b21\u306e\u884c\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<br \/>\nShift\uff0bTab\u306fTab\u3068\u9006\u306b\u79fb\u52d5\u3057\u307e\u3059\u3002<br \/>\n\u203bForm\u5185\u306b\u4ee5\u4e0b\u3092\u8a18\u8ff0\u3057\u3066\u3001\u305d\u306eForm\u306eDataGridView\u306e\u30c6\u30ad\u30b9\u30c8\u306e\u5217\u306b\u306fmyDataGridViewTextBoxColumn\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"mycode\">\nFriend Class myDataGridViewTextBoxColumn\nInherits DataGridViewTextBoxColumn\nPublic Overrides Property CellTemplate() As System.Windows.Forms.DataGridViewCell\nGet\nReturn New myDataGridViewTextBoxCell\nEnd Get\nSet(ByVal value As System.Windows.Forms.DataGridViewCell)\nMyBase.CellTemplate = value\nEnd Set\nEnd Property\nEnd Class\nFriend Class myDataGridViewTextBoxCell\nInherits DataGridViewTextBoxCell\nPublic Overrides ReadOnly Property EditType() As System.Type\nGet\nReturn GetType(myDataGridViewTextBoxEditingControl)\nEnd Get\nEnd Property\nEnd Class\nFriend Class myDataGridViewTextBoxEditingControl\nInherits DataGridViewTextBoxEditingControl\nPrivate Enum MoveTo\nNone = 0\nPrevCell = -1\nNextCell = 1\nEnd Enum\nProtected Overrides Sub OnPreviewKeyDown(e As PreviewKeyDownEventArgs)\nSelect Case e.KeyCode\nCase Keys.Enter, Keys.Tab\n' Enter\u30ad\u30fc\u3068Tab\u30ad\u30fc\u3092EditingControlWantsInputKey()\u3067\u62fe\u3048\u308b\u3088\u3046\u306b\u3059\u308b\ne.IsInputKey = True\nCase Else\nCall MyBase.OnPreviewKeyDown(e)\nEnd Select\nEnd Sub\nPublic Overrides Function EditingControlWantsInputKey(ByVal keyData As System.Windows.Forms.Keys, _\nByVal dataGridViewWantsInputKey As Boolean) As Boolean\nSelect Case keyData\nCase Keys.Left, Keys.Right, Keys.Enter, Keys.Tab, (Keys.Shift Or Keys.Tab)\n' \u30ab\u30fc\u30bd\u30eb\u79fb\u52d5\u30ad\u30fc\u306e\u62bc\u4e0b\u6642\u51e6\u7406\uff08\u5de6\u53f3\u30fbEnter\u30fbTab\uff09\nDim intMove As MoveTo = MoveTo.None\nDim blnWk As Boolean = False\nSelect Case keyData\nCase Keys.Enter, Keys.Tab\nintMove = MoveTo.NextCell\nCase (Keys.Shift Or Keys.Tab)\nintMove = MoveTo.PrevCell\nCase Keys.Left\nIf Me.SelectionStart = 0 Then blnWk = True\nIf Me.SelectionLength = Me.Text.Length Then blnWk = True\nIf blnWk = True Then\nintMove = MoveTo.PrevCell\nEnd If\nCase Keys.Right\nIf Me.SelectionStart = Me.Text.Length Then blnWk = True\nIf Me.SelectionLength = Me.Text.Length Then blnWk = True\nIf blnWk = True Then\nintMove = MoveTo.NextCell\nEnd If\nEnd Select\nIf intMove &#60;&#62; MoveTo.None Then\nDim grid As DataGridView = Me.EditingControlDataGridView\nCall Me.SetFocusNextCell(grid, intMove)\nEnd If\nReturn True\nCase Else\nReturn MyBase.EditingControlWantsInputKey(keyData, dataGridViewWantsInputKey)\nEnd Select\nEnd Function\nPrivate Sub SetFocusNextCell(ByVal grid As DataGridView, ByVal intMove As MoveTo)\nWith grid\nDim col As Integer = .CurrentCellAddress.X\nDim row As Integer = .CurrentCellAddress.Y\nDim r As Integer = row\nDim c As Integer\nDim blnWk As Boolean\nDim nextRow As Integer = -1\nDim nextCol As Integer = -1\nDim sc As Integer\nDim maxrow As Integer\nDim ccnt As Integer = .ColumnCount\nDim rcnt As Integer = .RowCount\n' \u76f4\u8fd1\u306e\u6709\u52b9\u306a\u30bb\u30eb\u306b\u30ab\u30fc\u30bd\u30eb\u3092\u79fb\u52d5\u3055\u305b\u308b\nSelect Case intMove\nCase MoveTo.PrevCell\nmaxrow = row - 1\nIf maxrow &#60; 0 Then maxrow = row\nFor r = row To maxrow Step -1\nsc = col - 1\nIf r &#60; row Then sc = ccnt - 1\nFor c = sc To 0 Step -1\nblnWk = True\n' \u9069\u5f53\u306b\u30c1\u30a7\u30c3\u30af\uff08Visible\u3068\u304bReadOnly\u3068\u304b\uff09\nIf blnWk = True Then\nnextRow = r\nnextCol = c\nExit For\nEnd If\nNext c\nIf nextRow &#62;= 0 Then Exit For\nNext r\nCase MoveTo.NextCell\nmaxrow = row + 1\nIf maxrow &#62;= rcnt Then maxrow = row\nFor r = row To maxrow\nsc = col + 1\nIf r &#62; row Then sc = 0\nFor c = sc To ccnt - 1\nblnWk = True\n' \u9069\u5f53\u306b\u30c1\u30a7\u30c3\u30af\uff08Visible\u3068\u304bReadOnly\u3068\u304b\uff09\nIf blnWk = True Then\nnextRow = r\nnextCol = c\nExit For\nEnd If\nNext c\nIf nextRow &#62;= 0 Then Exit For\nNext r\nEnd Select\nIf nextRow &#62;= 0 And nextCol &#62;= 0 Then\n.CurrentCell = .Rows(nextRow).Cells(nextCol)\nEnd If\nEnd With\nEnd Sub\nEnd Class\n<\/pre>\n<p>\u3053\u306e\u8fba\u3092\u53c2\u8003\u306b\u3055\u3057\u3066\u3082\u3089\u3044\u307e\u3057\u305f\u3002\u591a\u8b1d\u3002<br \/>\n<a href=\"http:\/\/dobon.net\/vb\/bbs\/log3-42\/25144.html\" target=\"_blank\">http:\/\/dobon.net\/vb\/bbs\/log3-42\/25144.html<\/a><br \/>\n<a href=\"http:\/\/www.atmarkit.co.jp\/bbs\/phpBB\/viewtopic.php?topic=41202&#038;forum=7\" target=\"_blank\">http:\/\/www.atmarkit.co.jp\/bbs\/phpBB\/viewtopic.php?topic=41202&#38;forum=7<\/a><br \/>\n<a href=\"http:\/\/www.atmarkit.co.jp\/bbs\/phpBB\/viewtopic.php?topic=47305&#038;forum=7\" target=\"_blank\">http:\/\/www.atmarkit.co.jp\/bbs\/phpBB\/viewtopic.php?topic=47305&#38;forum=7<\/a><br \/>\n<a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/ja\/vbexpressja\/thread\/fc1a0d8d-23d1-4a4e-a88c-f9a1edd81cff\" target=\"_blank\">http:\/\/social.msdn.microsoft.com\/Forums\/ja\/vbexpressja\/thread\/fc1a0d8d-23d1-4a4e-a88c-f9a1edd81cff<\/a><br \/>\n<a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/ja-JP\/csharpgeneralja\/thread\/234162d6-b3a6-4839-80b1-06641216f458\" target=\"_blank\">http:\/\/social.msdn.microsoft.com\/Forums\/ja-JP\/csharpgeneralja\/thread\/234162d6-b3a6-4839-80b1-06641216f458<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3048\u3048\u3068\u3001VB2010\u306eDataGridView\u3067\u77e2\u5370\u30ad\u30fc\u3068\u304bEnter\u30ad\u30fc\u3068\u304bTab\u30ad\u30fc\u3067\u30ab\u30fc\u30bd\u30eb\u79fb\u52d5\u3092\u3055\u305b\u305f\u3044\u306a\u30fc\u3068\u601d\u3063\u3066\u82e6\u6226\u3057\u305f\u306e\u3067\u30e1\u30e2\u3002 \u975e\u8868\u793a\u3084\u5165\u529b\u4e0d\u53ef\u306e\u30bb\u30eb\u3092\u98db\u3070\u3057\u3066\u79fb\u52d5\u3057\u307e\u3059\u3002\u7aef\u306e\u30bb\u30eb\u306e\u5834\u5408\u306f\u524d\u306e\u884c\u307e\u305f\u306f\u6b21\u306e<\/p>\n<p><a class=\"button\" href=\"https:\/\/keuko.exp.jp\/diary\/?p=4023\" title=\"More\">  \u7d9a\u304d\u3092\u8aad\u3080 \u2192<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-4023","post","type-post","status-publish","format-standard","hentry","category-job"],"_links":{"self":[{"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=\/wp\/v2\/posts\/4023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4023"}],"version-history":[{"count":0,"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=\/wp\/v2\/posts\/4023\/revisions"}],"wp:attachment":[{"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/keuko.exp.jp\/diary\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}