Hi Louisa,
I was looking for a similair sort of solution myself and was pleasently surprised how easy it was to implement.
I have to columns in my datagrid : itemType and itemCategory which I wanted both to have a combo.
First of declare variables for combobox before any procedures ie:
Private WithEvents ItemTypeComboBox As New ComboBox
Private WithEvents ItemCategoryComboBox As New ComboBox
now have a look at your grid column styles property and note the names of your columns. go back to code view and expand the "windows form designer generated code" and in the sub New() add after the Initlizecomponent call add your handlers, don't worry if intellisense doesn't pick up your columns it still works. for example (all 1 line)
AddHandler ItemTypeTextBox.TextBox.Enter, AddressOf CreateDropDownItemType
AddHandler ItemCategory.TextBox.Enter, AddressOf CreateDropDownItemCategory
where ItemTypeTextBox and ItemCategory are the name of your columns, the CreateDropDownItemType and CreateDropDownItemCategory after the address of are sub procedures to execute when you enter the textbox.
You must declare these procedures with parameters:
sender as object, e as system.eventargs
in these procedures you would tell the combobox where your datasource is and set the widths and add the control to the textbox, for example :
Private Sub CreateDropDownItemType(ByVal sender As Object, ByVal e As System.EventArgs)
Me.ItemTypeComboBox.DataSource = datasource
Me.ItemTypeComboBox.DisplayMember = displaymember
Me.ItemTypeComboBox.ValueMember = valuemember
ItemTypeComboBox.Width = ItemTypeTextBox.Width
ItemTypeTextBox.TextBox.Controls.Add(ItemTypeCombo Box)
End Sub
Private Sub CreateDropDownItemCategory(ByVal sender As Object, ByVal e As System.EventArgs)
Me.ItemCategoryComboBox.DataSource = datasource
Me.ItemCategoryComboBox.DisplayMember = displaymember
Me.ItemCategoryComboBox.ValueMember = valuemember
Me.ItemCategoryComboBox.Width = ItemCategory.Width
Me.ItemCategory.TextBox.Controls.Add(ItemCategoryC omboBox)
End Sub
and there you have it, adding handlers in this way should work for most controls, but i haven't tested it yet but I don't see why you wouldn't be able to add handlers to add a date time picker when you went to a textbox.
you would also have to add a event handler for the combobox selectionchanged event to update datagrid.currentCell value.
Just looked at the date, probably no use for you any more but maybe someone else will find this useful.
Gareth
-- WHEN FREEDOM IS OUTLAWED, ONLY THE OUTLAWS WILL BE FREE
|