主婦と.NETと犬のぶろぐ

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

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

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

昨日 の続きです。
今日は、
DataGridViewコントロール-バインド出来るデータソース(えムナウのプログラミングのページ)

DataGridViewコントロール-DataGridViewCellStyleクラス(えムナウのプログラミングのページ)
について、実装してみました。

ちょっとはまったのが、EnableHeadersVisualStyles に False を設定せねばいかんという事が抜けてたとこです。
VisualStyle が優先されちゃうんですね。

実行画像は、バインドに関しては省略します。想像通りです。たぶん。

■参考文献
DataGridViewコントロール-バインド出来るデータソース(えムナウのプログラミングのページ)
DataGridViewコントロール-DataGridViewCellStyleクラス(えムナウのプログラミングのページ)
DataGridViewCellStyle クラス
うさぎの穴をまっさかさま

■実行画像
色を変えたりして遊んだやつ
DataGridView

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 の追加 Dim dgView1 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-内部コントロールの種類", dgView1) Me.DataGridViewコントロール_内部コントロールの種類(dgView1)
' TabPage の追加 Dim dgView2 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-バインド出来るデータソース", dgView2) Me.DataGridViewコントロール_バインド出来るデータソース(dgView2)
' TabPage の追加 Dim dgView3 As DataGridView = New DataGridView Me.AddTabPage(tabCntrl, "DataGridViewコントロール-DataGridViewCellStyleクラス", dgView3) Me.DataGridViewコントロール_DataGridViewCellStyleクラス(dgView3)
tabCntrl.SelectedIndex = tabCntrl.TabPages.Count - 1 End Sub
Private Sub DataGridViewコントロール_DataGridViewCellStyleクラス(ByVal dgView As DataGridView)
' なんか適当なデータをバインドする Dim ds As DataSet = Me.CreateWankumaDataset() dgView.DataSource = ds ds.Tables(0).Columns.Add("NullColumn", GetType(String)) dgView.DataMember = ds.Tables(0).TableName
'' VisualStyles を使用しない dgView.EnableHeadersVisualStyles = False
'' 列ヘッダ Dim columnHeadersDefaultCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle columnHeadersDefaultCellStyle.BackColor = Color.DarkBlue columnHeadersDefaultCellStyle.ForeColor = Color.LightBlue columnHeadersDefaultCellStyle.Font = New Font("Goudy Stout", 10.0F, GraphicsUnit.Pixel) dgView.ColumnHeadersDefaultCellStyle = columnHeadersDefaultCellStyle
'' 行ヘッダ Dim rowHeadersDefaultCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle rowHeadersDefaultCellStyle.BackColor = Color.LightBlue rowHeadersDefaultCellStyle.ForeColor = Color.DarkBlue rowHeadersDefaultCellStyle.Font = New Font("Goudy Stout", 10.0F, GraphicsUnit.Pixel) dgView.RowHeadersDefaultCellStyle = rowHeadersDefaultCellStyle
'' 行のデフォルト Dim rowsDefaultCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle rowsDefaultCellStyle.BackColor = Color.Honeydew rowsDefaultCellStyle.ForeColor = Color.DarkGreen rowsDefaultCellStyle.NullValue = "(Null)" dgView.RowsDefaultCellStyle = rowsDefaultCellStyle
'' 奇数行 Dim alternatingRowsDefaultCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle alternatingRowsDefaultCellStyle.BackColor = Color.Ivory alternatingRowsDefaultCellStyle.ForeColor = Color.Red dgView.AlternatingRowsDefaultCellStyle = alternatingRowsDefaultCellStyle
'' セルのデフォルト Dim defaultCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle defaultCellStyle.Font = New Font("MS 明朝", 10.0F, FontStyle.Bold) dgView.DefaultCellStyle = defaultCellStyle
'' 2 行目の色を変える Dim jeanneCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle jeanneCellStyle.BackColor = Color.MediumTurquoise jeanneCellStyle.ForeColor = Color.White dgView.Rows(1).DefaultCellStyle = jeanneCellStyle
' '' NullColumn の色を変える(RowsDefaultCellStyle の方が優先して適用される) 'Dim nullColumnCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle 'nullColumnCellStyle.BackColor = Color.Black 'nullColumnCellStyle.ForeColor = Color.White 'dgView.Columns(2).DefaultCellStyle = nullColumnCellStyle
'' 4 行目、2 列目のセルの色を変える Dim naokoCellStyle As DataGridViewCellStyle = New DataGridViewCellStyle naokoCellStyle.BackColor = Color.Maroon naokoCellStyle.ForeColor = Color.White dgView.Rows(3).Cells(1).Style = naokoCellStyle
' カスタム描画 AddHandler dgView.CellPainting, AddressOf Me.CustomCellPaint
End Sub
Private Sub CustomCellPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
If e.ColumnIndex <> 1 OrElse e.RowIndex <> 0 Then Return
Dim rect As Rectangle = New Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 1, e.CellBounds.Height - 1) '// Render cell background Using brush As System.Drawing.Drawing2D.LinearGradientBrush _ = New System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.LightCoral, 0.0F) e.Graphics.FillRectangle(brush, rect) End Using
'// Render cell border Using pen As Pen = New Pen(System.Drawing.SystemColors.ControlDark) e.Graphics.DrawRectangle(pen, e.CellBounds.X - 1, e.CellBounds.Y - 1, e.CellBounds.Width, e.CellBounds.Height) End Using
'// Render cell value Dim format As StringFormat = New StringFormat() format.LineAlignment = StringAlignment.Center format.Alignment = StringAlignment.Far Using valueBrush As SolidBrush = New SolidBrush(e.CellStyle.ForeColor) e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font, valueBrush, rect) End Using
e.Handled = True End Sub
Private Sub DataGridViewコントロール_バインド出来るデータソース(ByVal dgView As DataGridView)
' IBindingList または ITypedList を実装する任意のクラス Dim ds As DataSet = Me.CreateWankumaDataset() ' DataSet をバインド dgView.DataSource = ds dgView.DataMember = ds.Tables(0).TableName
' DataTable をバインド dgView.DataSource = ds.Tables(0)
' DataView をバインド Dim dv As DataView = New DataView(ds.Tables(0)) dv.RowFilter = "[NAME] = 'なおこ(・∀・)'" dgView.DataSource = dv
' DataViewManager をバインド Dim dvm As DataViewManager = New DataViewManager(ds) dvm.DataViewSettings(ds.Tables(0).TableName).Sort = "[ID] DESC" dgView.DataSource = dvm dgView.DataMember = ds.Tables(0).TableName
'' IList を実装し、オブジェクトのインデックス付きコレクションを作成する任意のクラス ' ArrayList をバインド Dim petsArr As ArrayList = New ArrayList petsArr.Add(New Pet("ふじこ", 3)) petsArr.Add(New Pet("エデン", 2)) petsArr.Add(New Pet("オット", 0)) dgView.DataSource = petsArr
' 厳密に型指定されたオブジェクトの、厳密に型指定された IList ' Pet 型の配列をバインド Dim pets() As Pet = {New Pet("ふじこ", 3), New Pet("エデン", 2), New Pet("オット", -1)} dgView.DataSource = pets
' List(Of T) をバインド Dim petsList As List(Of Pet) = New List(Of Pet) petsList.Add(New Pet("ふじこ", 3)) petsList.Add(New Pet("エデン", 2)) petsList.Add(New Pet("オット", 10000)) dgView.DataSource = petsList
End Sub
#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
' WANKUMA Dataset の作成 Private Function CreateWankumaDataset() As DataSet Dim ds As DataSet = New DataSet("WANKUMA") Dim dt As DataTable = New DataTable("MEMBERS") Dim idColumn As DataColumn = New DataColumn("ID", GetType(Integer)) idColumn.AutoIncrement = True idColumn.AutoIncrementSeed = 1L idColumn.AutoIncrementStep = 1L idColumn.ReadOnly = True
dt.Columns.Add(idColumn) dt.Columns.Add("NAME", GetType(String))
Dim wankumaMembers As String() = _ {"中博俊", "じゃんぬねっと", "夏椰", "なおこ(・∀・)", _ "まゆりん", "Jitta", "trapemiya", "やねうらお", "囚人", _ "Moo", "maint", "επιστημη(えぴすてーめー)", _ "とっちゃん", "おぎわら", "えムナウ", "買太郎", _ "むたぐち", "aera", "taos", "ue", "ognac", _ "108bones", "ghost_shell", "黒龍", "koka", "inogucci", _ "ヽ(゚∀。)ノうぇね", "アクア", "n", "zee", "十郎", _ "Pandora", "刈歩 菜良", "R・田中一郎", "十兵衛(諸農)", _ "まさぶん", "まどか", "ゆき", "恣意の", "ひろえむ", _ "taka", "c", "DS7", "w", "沢渡真雪", "THREE-ONE", _ "Blue", "RAPT", "初音玲", "のぶさん", "ぽぴ王子", "g", "a", "s"}
For Each name As String In wankumaMembers Dim row As DataRow = dt.NewRow() row("NAME") = name dt.Rows.Add(row) Next
ds.Tables.Add(dt) Return ds End Function End Class
''' <summary> ''' ぺっとクラス ''' </summary> Public Class Pet
Private m_name As String Private m_age As Integer
Public Sub New(ByVal name As String, ByVal age As Integer) Me.m_name = name Me.m_age = age End Sub
Public ReadOnly Property Name() As String Get Return Me.m_name End Get End Property
Public ReadOnly Property Age() As Integer Get Return Me.m_age End Get End Property End Class

投稿日時 : 2006年12月20日 12:51

Feedback

# re: DataGridView(System.Windows.Forms.DataGridView)その2 2006/12/21 10:30 なおこ(・∀・)

表示カスタマイズの優先度についての記事がありましたね...
見落としてました。
http://mnow.wankuma.com/cs2005_datagridview_control8.html

# DataGridView(System.Windows.Forms.DataGridView)その3 2006/12/21 13:07 主婦と.NETと犬のぶろぐ

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

# JvccqptzXrhUqwZJjY 2014/08/27 23:25 http://crorkz.com/

NgvhHg great points altogether, you simply gained a brand new reader. What would you recommend about your post that you made some days ago? Any positive?

# ivMhtpaSXHlKnshqGP 2014/09/09 13:11 http://vente-sur-internet.com/luis-souto/

whoah this blog is excellent i really like studying your articles. Stay up the great paintings! You understand, lots of persons are looking round for this info, you can help them greatly.

# lpSGyZJQiQuOzHzG 2014/09/12 19:03 https://www.youtube.com/watch?v=jtXyUiBeflE

This website online can be a walk-through for all the info you wanted about this and didn't know who to ask. Glimpse right here, and also you'll positively discover it.

# cartier love bracelet discount replica 2015/07/29 18:34 refkcafq@aol.com

I have 6 domains with another provider and love them why I strayed I don't know. Stupidest move ever. I was registering a new domain and saw an add for Network Solutions. A little better pricing then my other provider so I thought I'd give them a try. I read all the fine print. Read my confirmation email carefully. Several months go by and I notice my monthly charge went from $2.95 a month to $65.00 a month. Now mind you my website was maybe 5 pages that is it. My cost at Go Daddy was $4.99 a month per website so this was outlandish. When I inquired how this was possible they said that the $2.95 was only a month introductory amount. Unbelievable to go from $2.95 to $65.00. I went back a reread everything and the order confirmation stated that the "Monthly recurring charge" was $2.95. When I asked them about this they stated that it doesn't matter what the confirmation email said for it was only an introductory amount end of story. Needless to say I instantly canceled. When I went to transfer my domain and get my website files they locked me out of my account. It has been 3 months and I am still battling them. My website has been down for 3 months after spending $1,000 of in marketing and advertising. All just went poof. The worst part is you talk to them on the phone and they really just don't care.
cartier love bracelet discount replica http://www.goldlovejewelry.com/

# love bracelet cartier prijs replica 2015/07/30 21:38 lyywiyjoh@aol.com

A fantastic interview Amanda. Perhaps Ms. Eastwood is trying to be a Marcel Duchamp of fashion, but all I see is her attention seeking fakery.聽
love bracelet cartier prijs replica http://www.release-charm.com/

# cartier armreif love 2015/08/01 17:00 sitgqh@aol.com

Have you considered about incorporating some social bookmarking buttons to these blogs. At least for facebook.
cartier armreif love http://www.bestcartierlovebracelet.com/de/

# love bracelet cartier preis replica 2015/08/03 1:34 gppxxgp@aol.com

This is a great post! I have to admit that I never notice name similarities in my books until I start revising. Great reminder.
love bracelet cartier preis replica http://www.fashionbangle.com/

# cartier gold love bracelet replica 2015/08/04 2:49 dcatwawlsq@aol.com

I'm going to at once catch the rss feed when i won't be able to in locating ones e-mail monthly subscription weblink as well as e-newsletter service. Have you got any kind of? Generously allow for my family realize so that I may sign up to. Many thanks. I'm going to at once catch the rss feed when i won't be able to in locating ones e-mail monthly subscription weblink as well as e-newsletter service. Have you got any kind of? Generously allow for my family realize so that I may sign up to. Many thanks.
cartier gold love bracelet replica http://www.beautiful-jewellery.com/

# cartier love bracelet 16 replica 2015/08/04 17:44 trfsqvwjm@aol.com

Хочу заказать рекламу у вас, куда писать?
cartier love bracelet 16 replica http://www.myjewelery.net/

# chanel tasche groä 2015/09/08 20:20 apnpdwvzr@aol.com

I supplement with occasional cold-processed whey protein from grass-fed cows, which I feel is the best choice for a protein supplement. It *is* more costly but I definitely feel like I’m getting more out of it compared to the highly processed whey exposed to extremely high temps.
chanel tasche groä http://www.replicasbag.net/de/-c87_90/

# cartier falso bracciale love 2015/09/16 21:52 wnckzk@aol.com

Patents law must keep itself in step with the recent advancements. In today’s world, isolation of DNA is a routine technique. Way back in 1980s and 90s it was a miraculous thing to do. Therefore, I should think, claims reciting isolated DNA do not merit patent protection. Any comments?
cartier falso bracciale love http://www.replicacartierbracelet.ru/it/replica-love-bracelet-cartier-screwdriver-in-pink-gold-b6035616-p742/

# ブランドバッグ激安ブランド館 2017/07/11 21:16 myrlphjuben@outlook.com

ヴィトンコピー品激安販売店2017新品大SALE
ルイ・ヴィトンコピー品激安販売店の新品大SALEが開催します。
ルイヴィトン人気コピー品、コピールイヴィトン新作、ルイヴィトンダミエコピー、ルイヴィトンモノグラムコピー、コピーブランド腕時計…
いろいろ新品が続々登場します。バッグ、靴、帽子、スカーフ...
お綺麗を展示ため、ぜひおすすめの逸品です。
時間の制限がない、いつでもご愛用頂きます。
ブランドバッグ激安ブランド館 http://www.baggobuy.com

タイトル  
名前  
Url
コメント