Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > MultiColumn ComboBox Column in datagridview
 

MultiColumn ComboBox Column in datagridview

Hi all

I have to show a column in the datagrid view

which is having a combobox with the multiple columns

So how should i start

Make a user control of multicolumn combo box ]then add  that in tha column of the datgridview

How to craete that control (MultiCOlumn COmbo)

 

Any source ,link,help, direction is highly appreciated

 

Thanks a lot

Hema Chaudhry  Monday, January 09, 2006 5:15 AM

I don't know of any sample code for this. I guess the first thing is to find out how to create a multi column combobox, then take the custom calendar cell sample and change the editing contorl to be your multi column combobox. Good luck!

 

-mark

DataGridView Program Manager

Microsoft

This post is provided "as-is"

 

Mark Rideout  Tuesday, January 10, 2006 5:40 PM

I don't know of any sample code for this. I guess the first thing is to find out how to create a multi column combobox, then take the custom calendar cell sample and change the editing contorl to be your multi column combobox. Good luck!

 

-mark

DataGridView Program Manager

Microsoft

This post is provided "as-is"

 

Mark Rideout  Tuesday, January 10, 2006 5:40 PM

Thanks for your kind support

But if u get any clue

Plz get back to me.

 

Thanks a bunch again

Thanks & Regards

Hema Chaudhry

 

Hema Chaudhry  Wednesday, January 11, 2006 10:39 AM
Mark Rideout wrote:

I don't know of any sample code for this. I guess the first thing is to find out how to create a multi column combobox, then take the custom calendar cell sample and change the editing contorl to be your multi column combobox. Good luck!

-mark

DataGridView Program Manager

Microsoft

This post is provided "as-is"

found this in my problem

i have my own multi column combo box

and i have also the custom calendar cell sample

but im having hardtime editing those edting control code.. :(

in vb.net

drachx  Wednesday, January 25, 2006 7:25 AM

Hi Hema,

Have you figure out how to create a multi-column combobox in the DataGridView?

Can you guide me through on this or do you have a sample code for it?

Thanks

nkotb  Sunday, March 19, 2006 8:59 AM

Hi nkotb,

Till Now even I also not get any solution for this

There is nothing to try

I have triec like the Custom Calender Control in Datagridview

But that is alos not successful.

But if u got any solution , clue plz revert back to me also.

Thanks a lot

Hr_Ind  Monday, March 20, 2006 5:15 AM

Hi HR,

How long you have been trying on this issue? Do you get any advice from else where?

nkotb  Monday, March 20, 2006 6:14 AM

Class for Custom Calender Cell in datagridview

Public Class CalendarColumn

Inherits DataGridViewColumn

Public Sub New()

MyBase.New(New CalendarCell())

End Sub

Public Overrides Property CellTemplate() As DataGridViewCell

Get

Return MyBase.CellTemplate

End Get

Set(ByVal value As DataGridViewCell)

' Ensure that the cell used for the template is a CalendarCell.

If Not (value Is Nothing) AndAlso _

Not value.GetType().IsAssignableFrom(GetType(CalendarCell)) _

Then

Throw New InvalidCastException("Must be a CalendarCell")

End If

MyBase.CellTemplate = value

End Set

End Property

End Class

Public Class CalendarCell

Inherits DataGridViewTextBoxCell

Public Sub New()

' Use the short date format.

Me.Style.Format = "d"

End Sub

Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _

ByVal initialFormattedValue As Object, _

ByVal dataGridViewCellStyle As DataGridViewCellStyle)

' Set the value of the editing control to the current cell value.

MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _

dataGridViewCellStyle)

Dim ctl As CalendarEditingControl = _

CType(DataGridView.EditingControl, CalendarEditingControl)

If CStr(Me.Value) = "" Then Me.Value = DateTime.Now

ctl.Value = CType(Me.Value, DateTime)

End Sub

Public Overrides ReadOnly Property EditType() As Type

Get

' Return the type of the editing contol that CalendarCell uses.

Return GetType(CalendarEditingControl)

End Get

End Property

Public Overrides ReadOnly Property ValueType() As Type

Get

' Return the type of the value that CalendarCell contains.

Return GetType(DateTime)

End Get

End Property

Public Overrides ReadOnly Property DefaultNewRowValue() As Object

Get

' Use the current date and time as the default value.

Return DateTime.Now

End Get

End Property

End Class

Class CalendarEditingControl

Inherits DateTimePicker

Implements IDataGridViewEditingControl

Private dataGridViewControl As DataGridView

Private valueIsChanged As Boolean = False

Private rowIndexNum As Integer

Public Sub New()

Me.Format = DateTimePickerFormat.Short

End Sub

Public Property EditingControlFormattedValue() As Object _

Implements IDataGridViewEditingControl.EditingControlFormattedValue

Get

Return Me.Value.ToShortDateString()

End Get

Set(ByVal value As Object)

If TypeOf value Is [String] Then

Me.Value = DateTime.Parse(CStr(value))

End If

End Set

End Property

Public Function GetEditingControlFormattedValue(ByVal context _

As DataGridViewDataErrorContexts) As Object _

Implements IDataGridViewEditingControl.GetEditingControlFormattedValue

Return Me.Value.ToShortDateString()

End Function

Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As _

DataGridViewCellStyle) _

Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl

Me.Font = dataGridViewCellStyle.Font

Me.CalendarForeColor = dataGridViewCellStyle.ForeColor

Me.CalendarMonthBackground = dataGridViewCellStyle.BackColor

End Sub

Public Property EditingControlRowIndex() As Integer _

Implements IDataGridViewEditingControl.EditingControlRowIndex

Get

Return rowIndexNum

End Get

Set(ByVal value As Integer)

rowIndexNum = value

End Set

End Property

Public Function EditingControlWantsInputKey(ByVal key As Keys, _

ByVal dataGridViewWantsInputKey As Boolean) As Boolean _

Implements IDataGridViewEditingControl.EditingControlWantsInputKey

' Let the DateTimePicker handle the keys listed.

Select Case key And Keys.KeyCode

Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _

Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

Return True

Case Else

Return False

End Select

End Function

Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _

Implements IDataGridViewEditingControl.PrepareEditingControlForEdit

' No preparation needs to be done.

End Sub

Public ReadOnly Property RepositionEditingControlOnValueChange() _

As Boolean Implements _

IDataGridViewEditingControl.RepositionEditingControlOnValueChange

Get

Return False

End Get

End Property

Public Property EditingControlDataGridView() As DataGridView _

Implements IDataGridViewEditingControl.EditingControlDataGridView

Get

Return dataGridViewControl

End Get

Set(ByVal value As DataGridView)

dataGridViewControl = value

End Set

End Property

Public Property EditingControlValueChanged() As Boolean _

Implements IDataGridViewEditingControl.EditingControlValueChanged

Get

Return valueIsChanged

End Get

Set(ByVal value As Boolean)

valueIsChanged = value

End Set

End Property

Public ReadOnly Property EditingControlCursor() As Cursor _

Implements IDataGridViewEditingControl.EditingPanelCursor

Get

Return MyBase.Cursor

End Get

End Property

Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)

' Notify the DataGridView that the contents of the cell have changed.

valueIsChanged = True

Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)

MyBase.OnValueChanged(eventargs)

End Sub

End Class

nirav4343  Friday, September 21, 2007 6:36 AM
MehulBS  Monday, July 28, 2008 11:13 AM
i came across this thread from a search and i have a sample that may be of some help here. i have seen others asking for multicolum combobox for datagridview cell.

on my website i have a sample code and i believe a project also which shows how to use a control from the toolbox as the editing control for the datagridview. basically it overrides the editing control and places a control over the cell when editing. it uses a textbox but it could be easily modified to use any control you want. i don't know about multicolumn combobox but i would suggest instead to use another datagridview as the editing control. it could be formatted to look like a combobox without gridlines, etc...

the sample will show you how you can easily modify it for any control. the sample and project are named - use a textbox as the editing control for a datagridview.

hope this helps
FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial
Jeff - www.SRSoft.us  Sunday, July 12, 2009 11:32 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom Object in DataGrid
• Connecting to a database in SQl2000, authentication error
• Changing the column type at runtime
• DataGridView - Invisible Cell Error Update
• Problem Data Source
• How to delete rows using DataGridView bound to DataSet using DataBindingSource?
• DataGrid Control
• Updatable DataGridView with columns from multiple tables
• Importing contact's details in to custom form
• add textbox in datagrid