主婦と.NETと犬のぶろぐ

奥様 と プログラム と お犬様 の 楽しい日常

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

DataGridView(System.Windows.Forms.DataGridView)その3

今日は、
DataGridViewコントロール-行・列を固定する(えムナウのプログラミングのページ)
と、
方法 : Windows フォーム DataGridView Cells でコントロールをホストする
を参考に遊んでみました。

DataGridView は Excel の機能でいう、ウィンドウ枠の固定の様な事ができます。便利便利。
もう一個は、MaskedTextBox をもつ DataGridView の列 を作ってみました。
これは、参考にした 方法 : Windows フォーム DataGridView Cells でコントロールをホストする
DateTimePicker 列をそのまま、MaskedTextBox に変えてみました。
結構悩んだのが、Mask 文字列をどうやってコントロールに伝えるか。
引数付きのコンストラクタはダメーとか言われたりして、苦肉の策で OwningColumn を MaskedColumn にキャストして Mask を渡す事にしました。

■参考文献
DataGridViewコントロール-行・列を固定する(えムナウのプログラミングのページ)
方法 : Windows フォーム DataGridView Cells でコントロールをホストする

■実行画像
行を固定したの
DataGridView 行を固定

行と列を固定したの
DataGridView 行と列を固定

MaskedTextBox 列
DataGridView MaskedTextBox 列

Public Class DataGridViewTest

Private Sub DataGridViewTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = New Size(600, 300)
'' TabControl に DataGridView を描画します。 Dim tabCntrl As TabControl = New TabControl Me.Controls.Add(tabCntrl) tabCntrl.Dock = DockStyle.Fill
tabCntrl.TabPages.Clear() ' TabPage の追加(2006.12.19 DataGridView(System.Windows.Forms.DataGridView)その1参照) Dim dgView1 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-内部コントロールの種類", dgView1) Me.DataGridViewコントロール_内部コントロールの種類(dgView1)
' TabPage の追加(2006.12.20 DataGridView(System.Windows.Forms.DataGridView)その2参照) Dim dgView2 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-バインド出来るデータソース", dgView2) Me.DataGridViewコントロール_バインド出来るデータソース(dgView2)
' TabPage の追加(2006.12.20 DataGridView(System.Windows.Forms.DataGridView)その2参照) Dim dgView3 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-DataGridViewCellStyleクラス", dgView3) Me.DataGridViewコントロール_DataGridViewCellStyleクラス(dgView3)
' TabPage の追加(2006.12.21) Dim dgView4 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-行を固定する", dgView4) Me.DataGridViewコントロール_行を固定する(dgView4)
' TabPage の追加(2006.12.21) Dim dgView5 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-行・列を固定する", dgView5) Me.DataGridViewコントロール_行・列を固定する(dgView5)
' TabPage の追加(2006.12.21) Dim dgView6 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "Mask列を追加する", dgView6) Me.Mask列を追加する(dgView6)
tabCntrl.SelectedIndex = tabCntrl.TabPages.Count - 1 End Sub
Private Sub DataGridViewコントロール_行を固定する(ByVal dgView As DataGridView)
' なんか適当なデータをバインドする Dim ds As DataSet = Me.CreateWankumaDataset() dgView.DataSource = ds ds.Tables(0).Columns.Add("NullColumn1", GetType(String)) ds.Tables(0).Columns.Add("NullColumn2", GetType(String)) ds.Tables(0).Columns.Add("NullColumn3", GetType(String)) ds.Tables(0).Columns.Add("NullColumn4", GetType(String)) ds.Tables(0).Columns.Add("NullColumn5", GetType(String)) dgView.DataMember = ds.Tables(0).TableName
' 2 行目で固定する dgView.Rows(1).Frozen = True ' 区分線を太くする dgView.Rows(1).DividerHeight = 5 End Sub
Private Sub DataGridViewコントロール_行・列を固定する(ByVal dgView As DataGridView)
' なんか適当なデータをバインドする Dim ds As DataSet = Me.CreateWankumaDataset() dgView.DataSource = ds ds.Tables(0).Columns.Add("NullColumn1", GetType(String)) ds.Tables(0).Columns.Add("NullColumn2", GetType(String)) ds.Tables(0).Columns.Add("NullColumn3", GetType(String)) ds.Tables(0).Columns.Add("NullColumn4", GetType(String)) ds.Tables(0).Columns.Add("NullColumn5", GetType(String)) dgView.DataMember = ds.Tables(0).TableName
' 2 行目で固定する dgView.Rows(1).Frozen = True ' 2 列目で固定する dgView.Columns(1).Frozen = True
' 区分線を太くする dgView.Columns(1).DividerWidth = 5 dgView.Rows(1).DividerHeight = 5
End Sub
Private Sub Mask列を追加する(ByVal dgView As DataGridView) Dim maskCol As MaskedColumn = New MaskedColumn() maskCol.Mask = "000-0000" dgView.Columns.Add(maskCol) dgView.RowCount = 5 End Sub
#Region "Private Sub DataGridViewコントロール_DataGridViewCellStyleクラス"
DataGridView(System.Windows.Forms.DataGridView)その2参照
#End Region
#Region "Private Sub CustomCellPaint"
DataGridView(System.Windows.Forms.DataGridView)その2参照
#End Region
#Region "Private Sub DataGridViewコントロール_バインド出来るデータソース"
DataGridView(System.Windows.Forms.DataGridView)その2参照
#End Region
#Region "Private Sub DataGridViewコントロール_内部コントロールの種類"
DataGridView(System.Windows.Forms.DataGridView)その1参照
#End Region
#Region "Private Sub OnCellContentClick"
DataGridView(System.Windows.Forms.DataGridView)その1参照
#End Region
#Region "Private Sub AddTabPage"
DataGridView(System.Windows.Forms.DataGridView)その1参照
#End Region
#Region "Private Function CreateWankumaDataset"
DataGridView(System.Windows.Forms.DataGridView)その2参照
#End Region
End Class
#Region "Public Class Pet"
DataGridView(System.Windows.Forms.DataGridView)その2参照
#End Region
''' ''' MaskedEditingControl ''' Public Class MaskedEditingControl Inherits MaskedTextBox Implements IDataGridViewEditingControl
Private dataGridViewControl As DataGridView Private valueIsChanged As Boolean = False Private rowIndexNum As Integer
Public Sub New() End Sub
Public Property EditingControlFormattedValue() As Object _ Implements IDataGridViewEditingControl.EditingControlFormattedValue
Get Return MyBase.Text End Get
Set(ByVal value As Object) If TypeOf value Is [String] Then MyBase.Text = Convert.ToString(value) End If End Set
End Property
Public Function GetEditingControlFormattedValue(ByVal context _ As DataGridViewDataErrorContexts) As Object _ Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
Return MyBase.Text
End Function
Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As _ DataGridViewCellStyle) _ Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
MyBase.Font = dataGridViewCellStyle.Font MyBase.BackColor = dataGridViewCellStyle.BackColor MyBase.ForeColor = dataGridViewCellStyle.ForeColor MyBase.BorderStyle = Windows.Forms.BorderStyle.None End Sub
Public Property EditingControlRowIndex() As Integer _ Implements IDataGridViewEditingControl.EditingControlRowIndex
Get Return Me.rowIndexNum End Get Set(ByVal value As Integer) Me.rowIndexNum = value End Set
End Property
Public Function EditingControlWantsInputKey(ByVal key As Keys, _ ByVal dataGridViewWantsInputKey As Boolean) As Boolean _ Implements IDataGridViewEditingControl.EditingControlWantsInputKey Return True End Function
Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _ Implements IDataGridViewEditingControl.PrepareEditingControlForEdit End Sub
Public ReadOnly Property RepositionEditingControlOnValueChange() _ As Boolean Implements _ IDataGridViewEditingControl.RepositionEditingControlOnValueChange
Get Return False End Get
End Property
Public Property EditingControlDataGridView() As DataGridView _ Implements IDataGridViewEditingControl.EditingControlDataGridView
Get Return Me.dataGridViewControl End Get Set(ByVal value As DataGridView) Me.dataGridViewControl = value End Set
End Property
Public Property EditingControlValueChanged() As Boolean _ Implements IDataGridViewEditingControl.EditingControlValueChanged
Get Return Me.valueIsChanged End Get Set(ByVal value As Boolean) Me.valueIsChanged = value End Set
End Property
Public ReadOnly Property EditingControlCursor() As Cursor _ Implements IDataGridViewEditingControl.EditingPanelCursor
Get Return MyBase.Cursor End Get
End Property
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs) Me.valueIsChanged = True Me.EditingControlDataGridView.NotifyCurrentCellDirty(True) MyBase.OnTextChanged(e) End Sub
End Class ''' ''' MaskedCell ''' Public Class MaskedCell Inherits DataGridViewTextBoxCell
Public Sub New() End Sub
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _ ByVal initialFormattedValue As Object, _ ByVal dataGridViewCellStyle As DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _ dataGridViewCellStyle)
Dim ctl As MaskedEditingControl = _ DirectCast(DataGridView.EditingControl, MaskedEditingControl) ctl.Mask = DirectCast(MyBase.OwningColumn, MaskedColumn).Mask ctl.Text = Convert.ToString(Me.Value)
End Sub
Public Overrides ReadOnly Property EditType() As Type Get Return GetType(MaskedEditingControl) End Get End Property
Public Overrides ReadOnly Property ValueType() As Type Get Return GetType(String) End Get End Property
Public Overrides ReadOnly Property DefaultNewRowValue() As Object Get Return String.Empty End Get End Property
End Class
''' ''' MaskedColumn ''' Public Class MaskedColumn Inherits DataGridViewColumn
Private m_mask As String
Public Property Mask() As String Get Return Me.m_mask End Get Set(ByVal value As String) Me.m_mask = value End Set End Property
Public Sub New() MyBase.New(New MaskedCell()) End Sub
Public Overrides Property CellTemplate() As DataGridViewCell Get Return MyBase.CellTemplate End Get Set(ByVal value As DataGridViewCell) If Not (value Is Nothing) AndAlso _ Not value.GetType().IsAssignableFrom(GetType(MaskedCell)) _ Then Throw New InvalidCastException("Must be a MaskedCell") End If MyBase.CellTemplate = value End Set End Property
End Class

投稿日時 : 2006年12月21日 13:07

Feedback

# re: DataGridView(System.Windows.Forms.DataGridView)その3 2006/12/21 16:34 えムナウ

>結構悩んだのが、Mask 文字列をどうやってコントロールに伝えるか。
public override object Clone() を実装してください。
http://mnow.wankuma.com/cs2005_datagridview_control5.html

# re: DataGridView(System.Windows.Forms.DataGridView)その3 2006/12/21 19:03 アクア

すっごく参考になります。

こんな事出来るんだ~って普通に感心しました。
しかも連日。

# あ~、テストしたい~! 確認したい~!
# でも、もう少し今やってることをやっとかないと全部中途半端な事に…

# re: DataGridView(System.Windows.Forms.DataGridView)その3 2006/12/21 19:28 なおこ(・∀・)

>> えムナウさん
「方法 : Windows フォーム DataGridView Cells でコントロールをホストする」より引用。
-------------------------------------------
メモ
DataGridViewCell や DataGridViewColumn から派生したクラスに新しいプロパティを追加するときは、Clone メソッドをオーバーライドし、複製操作時に新しいプロパティをコピーする必要があります。また、基本クラスの Clone メソッドを呼び出して、基本クラスのプロパティを新しいセルまたは列にコピーする必要もあります。
-------------------------------------------
思いっきり書いてありました...orz

今日メッセであーじゃこーじゃとアドバイスいただいた
改良版を明日アップします。

>> アクアさん
私も手探りでやってます。
結構おもしろいですね。

# re: DataGridView(System.Windows.Forms.DataGridView)その3 2006/12/22 12:59 Jitta

> 行を固定したの
こ 越えられない壁???

# re: DataGridView(System.Windows.Forms.DataGridView)その3 2006/12/22 14:42 なおこ(・∀・)

>> Jitta さん
2 行で固定しているのに意味はないですよw

# ryXItSgzOsdbUBiGG 2014/08/28 10:19 http://crorkz.com/

gACqVE I am always invstigating online for tips that can aid me. Thx!

# rvMBJRKKikBshc 2014/09/05 10:33 http://www.keralatourpackages.com

I loved your post.Thanks Again. Really Great.

# XAKxWWsIEvQ 2014/09/09 10:00 http://vender-por-internet.net/luis-souto/

I keep listening to the news lecture about getting boundless online grant applications so I have been looking around for the best site to get one. Could you advise me please, where could i get some?

# zwfKdYOsdXiMSzeiE 2014/09/11 18:06 http://swiss-vps.com/products/windows-vps/

I've read some excellent stuff here. Certainly worth bookmarking for revisiting. I surprise how much attempt you set to make any such fantastic informative web site.

# oKSkuVcgMHat 2014/09/18 17:07 http://cool-photos.info/story.php?id=94094

CN4l0m I think this is a real great article post.Thanks Again. Keep writing.

# KbCNnmxFhrTm 2015/01/11 16:50 varlog

BbLyf0 http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com

# nlPOCWcAJxNZY 2015/01/26 8:23 Sterling

Is there ? http://sacraliturgia2013-italy.com/don-bux/ klonopin 20 mg The exhibition is full of sophisticated techniques like this that were designed to enhance our understanding of how human bodies work, and not just how they appear internally. At first glance, with their tangled tendons and masses of muscle, Leonardo’s dispassionate pen-and-ink studies can appear like aerial photographs of motorway spaghetti junctions. But compared with the blood-and-guts chaos of the human body, in which everything is crushed up against each other, they are models of clarity and insight – as the accompanying medical imagery makes plain.

# BATdFoARgNE 2015/01/26 8:23 Ernie

Would you like a receipt? http://www.loakal.com/contact/ klonopin 1mg cost However, please note - if you block/delete all cookies, some features of our websites, such as remembering your login details, or the site branding for your local newspaper may not function as a result.

# uMDjKKyMxhh 2015/01/27 14:40 Ava

I'd like , please http://www.hollandpompgroep.nl/atex zopiclone price For the better part of the last six years, the world has struggled with the financial aftermath of the 2007 financial crisis, resulting in today�s aftermath of under-capitalized institutions and insolvent sovereign governments. Can we afford to continue as we are for another five, ten years?

# NxVjpoNRFRvfxZpZ 2015/01/28 19:55 Cyrus

I like watching football http://www.video-to-flash.com/video_to_flv/ rivotril clonazepam 2.5 mg gotas Amazon has been deadly for literary culture in other respects. It bullies publishers on pricing, especially for e-books, and therefore significantly reduces their ability to provide advances to young and not yet established authors. What’s more, it insists on offering used books in the same space as new ones, tempting the consumer to save money and cut out the author and publisher entirely. (The same is true for CDs and DVDs.) If Amazon succeeds in its quest to resell “used” e-books, it will likely destroy that revenue stream for authors and publishers entirely. (And yes, I think Kindle Singles are a wonderful development for long-form reporting, but, once again, the compensation structure is unlikely to provide authors with the kind of income that allows for regular food and drink, much less college tuition.)

# fIDjuCnTaHSIee 2015/01/28 19:55 Conrad

Some First Class stamps http://www.centernewton.org/plan/ clonazepam dose mg/kg Since fruit flies are widely used in genetic studies, researchers can draw on the wealth of knowledge about various fruit fly strains to figure out both the anatomical and genetic roots of how TBI affects different individuals.  

# xEqgxfozJeumHSVY 2015/02/04 7:20 Vida

We were at school together http://www.pointreyesseashore.com/blog/ generic for bactrim On June 29, 2010, NOAA Fisheries provided notice that it was initiating a status review of the eastern Steller sea lion and requested public comment. During the comment period, NOAA Fisheries received two petitions to delist the eastern Steller sea lion: one from the states of Washington and Oregon; and one from the state of Alaska.

# BBPyOrFiulgkq 2015/02/05 12:23 Numbers

Languages http://www.retendo.com.pl/sklep/ purchase domperidone canada The Belgian government, mindful of budget savings it has forced on the public, has said this should help cap costs. Even royalist Belgians feel they know little about Philippe, who has appeared reserved in public, in contrast to his more outgoing father.

# RmIhtKDpgBMELd 2015/02/06 16:44 Diego

How many would you like? http://www.wonderbra.ca/about-us/ tenormin tablets * U.S. Senate negotiations to bring a fiscal crisis to an end showed signsof progress on Sunday, but there were no guarantees the federal governmentshutdown was about to end or that a historic debt default would be avoided.

# MpkQaulWZMbfUkdOH 2015/02/07 20:51 Edwardo

Your account's overdrawn http://www.sullivans.com.au/tours/ azithromycin 500mg tablets price in india It�s 1 p.m. on Sept. 11, what would have been Bear Bryant�s 100th birthday, and Cutcliffe strolls through his spacious fourth-floor office in the Yoh Football Center. On one shelf, there are his trophies for Coach of the Year honors in both the SEC and ACC. Below them are the college jerseys of Eli and Peyton � Ole Miss navy blue and Tennessee orange, respectively. Balls autographed by both rest on an angle nearby.

# USrHfiYAQQSYHs 2015/02/08 14:21 Elisha

I'm not sure http://atecuccod.com/index.php/aszf loan amortize LONDON, Aug 23 (Reuters) - Britain's blue chip shares inchedup on Friday against a backdrop of economic recovery takinghold, led by specialty chemical maker Croda International on arating hike from Deutsche Bank.

# bRZilaQjISaucInSPD 2015/02/09 22:52 Gregory

We're at university together http://whistlingduck.net/blog/ i need a 5000 dollar loan but have bad credit "The current tools of competition law are totally unsuitedto the fast-changing world of the Internet," Pellerin said inthe interview conducted in French. "To get out of this impasse,Europe needs a regulatory authority to act on an ex-ante basis,as soon as conflicts and abuse emerge on the part of internetplatforms."

# yynYrGEsdJXy 2015/02/10 5:53 Jeremiah

I'm interested in http://www.milliput.com/about.html Aciclovir Tablet U.S. Bankruptcy Court Judge Steven Rhodes, who is overseeing Detroit's bankruptcy, appears to be taking some action to help the aggrieved civil suit plaintiffs. On Friday, he suggested that a committee be formed to handle what he expects will be a huge volume of requests from civil plaintiffs seeking relief. While all civil suits have been frozen, plaintiffs can still petition the court and ask for a continuance.

# uNFIGTsRPEnuhg 2015/02/11 7:06 Colby

I saw your advert in the paper http://thisisaway.org/projects/ cash drawer serial Pittsburgh's $150 million stormwater management plan will debut next week, but better storm sewers couldn't prevent the flash flooding that occurs more and more frequently in Western Pennsylvania, wet weather experts said.

# pPymcEWeHmZwjKF 2015/02/25 7:54 Marquis

Where do you live? http://www.orthopaedic-institute.org/fundraising.html domperidone price list Whilst escaping the city lights on camels from Sharm el Sheikh, to the desert for a night of stars and feasting, you are immediately rewarded by the display of one of the most spectacular sunsets on earth. With the aid of your guide, and viewing through telescopes, you will see the universe as it is meant to be seen. Transporting you on a faraway journey, out into space, encountering a vast vault of sky studded with thousands of twinkling stars, touching on specific constellations, galaxies and the splendours of the solar system. After, you can indulge in an authentic Bedouin candlelight supper, including the making of Bedouin bread.

# LXUrFrjjOuQCB 2015/02/25 7:54 Tony

I'm self-employed http://spid.it/gestione-rischio-clinico/ phenergan cost NEW YORK - Wall Street is bracing for a wave of economic reports next week, including the August jobs report, which might prove decisive in determining whether the economy is strong enough for the Federal Reserve to dial back its bond purchases in mid-September.

# askvWdPScFM 2015/02/25 7:54 Louie

Jonny was here http://www.alexisfacca.com/chemistry/ Micardis Mycard Just last month, the results of unannounced visits in five hospitals, including Beaumont Hospital in Dublin and the Mid Western Regional Maternity Hospital in Limerick, revealed a number of issues, including poor hand hygiene, dirty equipment and potential access by patients to dangerous chemicals, medication and syringes.

# TSSORuVWHSAWzsFOy 2015/02/26 11:05 Douglass

We were at school together http://www.angleseyonline.com/optimisation.html endep tablets 10mg The sale of IMG, whose clients include top tennis playerNovak Djokovic and supermodel Gisele Bundchen and which owns therights to numerous sports leagues, is being driven by thetrustee that runs the estate of Teddy Forstmann.

# LTrcHZlCWJOwobgGO 2015/02/26 11:05 Harvey

Best Site good looking http://www.tu-braunschweig-isl.de/LANDSCHAFTSARCHITEKTUR/ how much does diflucan cost But what drives such a peculiar turn in a typically subterranean group, known for operating in shadows and dark corners and speaking primarily to those who accompany them in often-destructive states of extremism?

# JLpLVhZimUOzOdb 2015/02/27 18:07 Matthew

I live here http://www.holysoakers.com/agence/ stromectol 3 mg Hitman John (The Executioner) Martorano, for example, made a deal with federal prosecutors that got him off on 20 murders but led to life in prison for another Bulger hitman, Stephen (The Rifleman) Flemmi.

# CkoMPMYnZKYfmrLX 2015/02/27 21:22 Rusty

Not in at the moment http://version22.com/contact/ latanoprost ophthalmic solution classification That�s according to a study co-published by a Delaware State University professor this week. Professor Noureddine Melikechi serves on the mission�s ChemCam Team, which concludes about 2 percent of Martian surface soil is made up of water.

# vaLyADDVboUwgE 2015/02/27 21:22 Reyes

I'll call back later http://www.muruniiduk.ee/products Tricor Cost The euro was down 0.43 percent at $1.3358. The dollarindex, which measures the greenback versus a basket of sixcurrencies, rose 0.51 percent to 81.315. Against the yen,the dollar rose 0.5 percent to 97.75.

# gUdNIVqllWMZlLyWv 2015/04/07 13:42 Jeromy

Another year http://www.europanova.eu/entreprendre-leurope/ bimatoprost online uk For President Barack Obama and supporters of his Wilsonian activism, America must act because a failure to act invites chaos. A stable global order where certain red lines are respected is in America’s interest.

# HCTYdRMnBh 2015/04/07 13:42 Jeffry

Gloomy tales http://www.theartofdining.co.uk/buy-tickets/ minoxidil 50 mg/g The Matrix tribute is perhaps a little old hat, but it’s the perfect framework for Saints Row’s systems and mish-mash of pop-culture and video game farce. Like the best spoofs, Saints Row IV works because it is overtly in love with the games it lampoons. Not much is sacred. The Saints send up moral choices (cure Cancer or World Hunger, Mr President?) graphic text adventures, stealth missions, video game romance. There’s always a danger that in appropriating other game’s work, Saints Row could just become a cheap knock-off. There are times when ennui sets in --a niggling feeling that you’ve played it all before-- but its tributes are done with such good-natured verve and self-deprecating wit that it contributes to a splutteringly funny and consistently entertaining video game.

# AuPYOIzAgD 2015/05/01 5:42 chaba

bPMmyW http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com

タイトル  
名前  
Url
コメント