That is good news! Great work guys! :thumb: :thumb:
This was real fun for me! :)
Printable View
That is good news! Great work guys! :thumb: :thumb:
This was real fun for me! :)
Me too ;)
Glad it worked (I love it when something you program blind works, but I couldn't be bothered to switch between solutions :)
You know, it wouldn't be far from the code we've got here to an extended DataGridView control where this was the default behaviour from all columns...
Well, I've got nothing else to do this evening...
LOL - good luck!!! :p
right got wife's brother's wedding tomorrow so going for drinks with the Groom for his last night of freedom ;)
Have a good wekend everyone :thumb: :D
I had a go - the coding worked out simple. It compiles, but it crashes when you try and run a form with one on. Works fine on the designer, and it generates no debug data, so I'm stumped...
Code:Public Class DataGridView2
Inherits Windows.Forms.DataGridView
Private Debounce As Boolean
Private Sub mCellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles MyBase.CellValidating
If Debounce Then
Debounce = False
Else
If TypeOf (Me.Columns(e.ColumnIndex)) Is DataGridViewComboBoxColumn Then
Dim comboBoxColumn As DataGridViewComboBoxColumn = CType(Me.Columns(e.ColumnIndex), DataGridViewComboBoxColumn)
If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
comboBoxColumn.Items.Add(e.FormattedValue)
Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = comboBoxColumn.Items(comboBoxColumn.Items.Count - 1)
End If
End If
End If
End Sub
Private Sub mColumnAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles MyBase.ColumnAdded
Debounce = True
End Sub
Private Sub DataGridView2_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MyBase.EditingControlShowing
If TypeOf (MyBase.Columns(MyBase.CurrentCell.ColumnIndex)) Is DataGridViewComboBoxColumn Then
Dim cb As ComboBox = CType(e.Control, ComboBox)
If (cb IsNot Nothing) Then
cb.DropDownStyle = ComboBoxStyle.DropDown
End If
End If
End Sub
End Class
Good morning!
This is what I did, javajawa :
I created a Class Library called DGVNew, the code looks like :
Just had to reference System.Windows.Forms etc.Code:Imports System.Windows.Forms.DataGridView
Public Class DGVNew
Inherits System.Windows.Forms.DataGridView
Private Debounce As Boolean
Private Sub DGVNew(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles MyBase.CellValidating
If Debounce Then
Debounce = False
Else
If TypeOf (Me.Columns(e.ColumnIndex)) Is System.Windows.Forms.DataGridViewComboBoxColumn Then
Dim comboBoxColumn As System.Windows.Forms.DataGridViewComboBoxColumn = CType(Me.Columns(e.ColumnIndex), System.Windows.Forms.DataGridViewComboBoxColumn)
If (Not comboBoxColumn.Items.Contains(e.FormattedValue)) Then
comboBoxColumn.Items.Add(e.FormattedValue)
Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = comboBoxColumn.Items(comboBoxColumn.Items.Count - 1)
End If
End If
End If
End Sub
Private Sub DGVNew(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles MyBase.ColumnAdded
Debounce = True
End Sub
Private Sub DGVNew_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MyBase.EditingControlShowing
If TypeOf (MyBase.Columns(MyBase.CurrentCell.ColumnIndex)) Is System.Windows.Forms.DataGridViewComboBoxColumn Then
Dim cb As System.Windows.Forms.ComboBox = CType(e.Control, System.Windows.Forms.ComboBox)
If (cb IsNot Nothing) Then
cb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown
End If
End If
End Sub
End Class
I Built DGVNew, in order to get the DLL.
Then, I created a separate project called DGVReplacement. I added the DGVNew.dll to the Toolbox, and added the following code :
It works perfectly, I've been testing it for some time now, and I haven't had any problems with it :)Code:Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim PenaltyColumn As New DataGridViewComboBoxColumn()
With PenaltyColumn
.DataPropertyName = "Penalty"
.HeaderText = "Penalty"
.DropDownWidth = 160
.Width = 90
.MaxDropDownItems = 3
.FlatStyle = FlatStyle.Flat
.Items.Add("1")
.Items.Add("11")
End With
DgvNew1.Columns.Add(PenaltyColumn)
End Sub
End Class
Should I include them in a zip ( note it's in 2005, as I have 2008 only at home )
Wouldn't mind the zip. My glitch probably came from the fact that I didn't bother with new projects, but just tore into the designer of the one I'd be using for this before. I probably made some mistake in there...
Here is the zip :)
I hope it helps!
Found the issue - when I changed the designers, I forgot that it CTypes everything to call BeginInit(), so it was CTypeing to the old version. Plus Debugger was told not to show me that bit (there should be some options to turn that off by default. You can get so much fine tuning out of the designer...)
Glad you got it solved!! :thumb:
Done some work on it - it now validates when you click elsewhere, or if you press enter. I can't work out why I need to do them sperately, but it works (surprisingly enough).
I love pointless class design...
Any objections on me setting up an FAQ covering DataGridViewComboboxColumns ( all these things we recenty did ) ¿
Or even on some of the fun things you can do with DGVs generally? LOL
Hi HannesTheGreat
Sounds good to me!! ;)
hi all.
i hav added a datagricview into winform. i hav added 2 combobx column into that datagrid view.
when i click the firsr combox column the second combobox column value should changed
this is m y reqiurment was. my first combox column is Itemid and second combobx column is Itemdescription.
as my reqirment when i chaged the itemid column the second column itemdescription should be changed.
some one pls help mw for this.
thnxs.
Rishad...