Click here to Skip to main content
15,167,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a DataGridView in my form and added items to DataGridViewComboBoxColumn, now I have a requirement to select multiple items from the DataGridViewComboBoxCell.

C#
DataGridViewComboBoxCell c = new DataGridViewComboBoxCell();

c.Items.Add("Red");
c.Items.Add("Green");
dgvDataIntegration.CurrentRow.Cells[3] = c;
dgvDataIntegration.CurrentRow.Cells[3].Value = c.Items[0];



Can you suggest the solution, how can we do this.


Thanks in advance.

Zulur
Posted
Updated 8-Apr-16 15:04pm
v2

The DataGridViewComboBoxColumn has no built in feature to support multiple selections.
Check this article on codeproject
Multi select Dropdown list in ASP.NET
and refer this link too :-)
How to: Host Controls in Windows Forms DataGridView Cells
   
some like this, i'm working on it at now but is slow when i have more than 100,000 rows


'the variables
#Region "Variables de control de selección"

Private _posicionInicialSeleccionada As Integer = -1
Private _posicionFinalSeleccionada As Integer = -1

#End Region


'the assigning
AddHandler CreditosFiscalesDataGridView.DataBindingComplete, AddressOf EjecucionFiscalHelper.Grid_DataBindingComplete_CentrarHeaders

'the method
Private Sub CreditosFiscalesDataGridView_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles CreditosFiscalesDataGridView.CellContentClick
Dim columnaActual As Integer = e.ColumnIndex
Dim rowActual As Integer = e.RowIndex
EjecucionFiscalHelper.VerificarSeleccion(rowActual, columnaActual, CreditosFiscalesDataGridView, _posicionInicialSeleccionada, _posicionFinalSeleccionada)
End Sub



'and the handler

Public Shared Sub VerificarSeleccion(ByVal rowActual As Integer, ByVal columnaActual As Integer, ByVal grid As DataGridView, ByRef _posicionInicialSeleccionada As Integer, ByRef _posicionFinalSeleccionada As Integer)

Dim posicionFinalAnteriorSeleccionada As Integer = -1

If grid.Columns(columnaActual).Name = ViewConstants.COLUMNA_SELECCION Then

If Not My.Computer.Keyboard.ShiftKeyDown Or _posicionInicialSeleccionada < 0 Then
_posicionFinalSeleccionada = -1
_posicionInicialSeleccionada = rowActual
Return
End If

If My.Computer.Keyboard.ShiftKeyDown Then

If _posicionInicialSeleccionada < 0 Then
_posicionInicialSeleccionada = rowActual
Else
If _posicionFinalSeleccionada >= 0 Then
posicionFinalAnteriorSeleccionada = _posicionFinalSeleccionada
End If
_posicionFinalSeleccionada = rowActual
End If

Dim posicionInicial As Integer = _posicionInicialSeleccionada
Dim posicionFinal As Integer = _posicionFinalSeleccionada

Dim direccionReversa As Boolean = False

If _posicionInicialSeleccionada > _posicionFinalSeleccionada And _posicionFinalSeleccionada > -1 Then
direccionReversa = True
End If

If posicionFinalAnteriorSeleccionada <= posicionFinal And direccionReversa And posicionFinalAnteriorSeleccionada > -1 Then
For Each row As DataGridViewRow In grid.Rows
If row.Index >= posicionFinalAnteriorSeleccionada And row.Index < posicionFinal Then
row.Cells(ViewConstants.COLUMNA_SELECCION).Value = False
End If
Next
Return
End If

If direccionReversa Then
For Each row As DataGridViewRow In grid.Rows
If row.Index > posicionFinal And row.Index <= posicionInicial Then
row.Cells(ViewConstants.COLUMNA_SELECCION).Value = True
End If
Next
Return
End If

If posicionFinal >= 0 And posicionFinalAnteriorSeleccionada > -1 Then
For Each row As DataGridViewRow In grid.Rows
If row.Index > posicionFinal And row.Index <= posicionFinalAnteriorSeleccionada Then
row.Cells(ViewConstants.COLUMNA_SELECCION).Value = False
End If
Next
End If

If posicionFinal >= 0 Then
For Each row As DataGridViewRow In grid.Rows
If row.Index >= posicionInicial And row.Index <= posicionFinal Then
row.Cells(ViewConstants.COLUMNA_SELECCION).Value = True
End If
Next
Return
End If

End If 'tecla shift
End If 'columna seleccion

End Sub
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900