-
July 29th, 2008, 08:07 AM
#1
[RESOLVED] DataGridViewComboBox problem!
Hi
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
Any help would be great! Thanks
-
July 29th, 2008, 08:36 AM
#2
Re: DataGridViewComboBox problem!
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.
*Guarantee may not be honoured.
-
July 29th, 2008, 08:42 AM
#3
Re: DataGridViewComboBox problem!
Why hello again - thanks for the help!
Code:
Dim Penalty As New DataGridViewComboBoxColumn with{.Name = "Penalty", .ReadOnly = False, .HeaderText = "Penalty", .Width = 40, .Visible = True}
didn't work - it had blue curly lines from the 'with' part onwards and the error said that End of statement was expected.
-
July 29th, 2008, 09:20 AM
#4
Re: DataGridViewComboBox problem!
You could try :
Code:
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.
-
July 29th, 2008, 09:27 AM
#5
Re: DataGridViewComboBox problem!
HanneSThEGreaT
Have you any idea why the values are not showing up in my ComboBoxes?
I have been looking over it for about 45mins now with no joy!
Visual Basic 2005 ver. 8.0.50727.867
-
July 29th, 2008, 09:49 AM
#6
Re: DataGridViewComboBox problem!
I was curious...
Hi brjames32!
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|