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...
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 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
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.
This is what I did, javajawa :
I created a Class Library called DGVNew, the code looks like :
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
Just had to reference System.Windows.Forms etc.
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 :
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
It works perfectly, I've been testing it for some time now, and I haven't had any problems with it
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...
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.
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...)
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.
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...
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.
Or even on some of the fun things you can do with DGVs generally? LOL
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 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.
* 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.