I have a DataGridView and am adding columns at runtime. One particular column is a ComboBox column. I have populated it but when I come to run the program, the ComboBoxes are in the relevant cells but don't drop down when you click on them! My code is below:
Code:
With DataGridView1
Dim Penalty As New DataGridViewComboBoxColumn
With Penalty
.Name = "Penalty"
.HeaderText = "Penalty"
.Width = 40
.Visible = True
.ReadOnly = False
.Items.Add("1")
.Items.Add("3")
.Items.Add("4")
.Items.Add("5")
.Items.Add("6")
.Items.Add("7")
.Items.Add("8")
.Items.Add("11")
End With
DataGridView1.Columns.Insert(6, Penalty)
End With
Me again!
Ok, firstly, don't nest With statements. I'm surprised that compiled, as .Name could a property of either. The following code (which is essentially the same) works on my computer:
Code:
Dim Penalty As New DataGridViewComboBoxColumn With {.Name = "Penalty", .ReadOnly = False, .HeaderText = "Penalty", .Width = 40, .Visible = True}
With Penalty.Items
.Add("1")
.Add("3")
.Add("4")
.Add("5")
.Add("6")
.Add("7")
.Add("8")
.Add("11")
End With
DataGridView1.Columns.Insert(6, Penalty)
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
Dim Penalty As New DataGridViewComboBoxColumn
With Penalty : .Name = "Penalty" : .ReadOnly = False : .HeaderText = "Penalty" : .Width = 40 : .Visible = True : End With
You use the colon ( : ) to chain multiple statements onto one line.
Very Bad practice IMHO, though - and, doesn't address your actual problem
Last edited by HanneSThEGreaT; July 29th, 2008 at 09:24 AM.
Well, I took your code exactly as it is on post#1, and it worked - just changed the column index. OK, my DataGridView was not bound to any datasource, but it works, as in the pic.
So, perhaps your problem is elsewhere ¿
Last edited by HanneSThEGreaT; June 14th, 2010 at 05:40 AM.
It might do if the program thinks that the column is bound at all. Are you populating manually or from a dataset?
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
I have attached the whole project to this reply. I can't find out what it could be! would be greatful if any of you can! The part we are discussing is in:
Code:
Private Sub cmdShow_Click
section.
Thanks a lot
Last edited by HanneSThEGreaT; July 30th, 2008 at 05:15 AM.
Reason: Tried to edit Rar into Zip, but failed
Without the database, it's kinda hard to run. I can spot anything wrong with that section, although with Option Strict, there a few warnings about (a couple of unused variables, which I think will get, and some functions that don't return values). Wish I could be of more help.
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
You could copy it, delete all the data, and type in some non-nonsensical stuff.
Help from me is always guaranteed!*
VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.
WOW - Access Database .rar well - it shrank from 5.9MB to 436KB!!! Also, I have attached the spreadhseets that the info is saved to - there is no problem saving though.
Anyway, here it is attached to this post . . . . .
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.