We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

GridDataBound - listbox

Thread ID:

Created:

Updated:

Platform:

Replies:

118025 Jan 21,2015 12:46 PM Feb 4,2015 08:15 AM Windows Forms 7
loading
Tags: GridDataBoundGrid(Classic)
Frank Piplak
Asked On January 21, 2015 12:46 PM

Hello,

I want to use a multicolumn listbox in a GridDataBound. I build a GridDataBound like this:

With GridDataBound
  .DataSource = vDbDataTable123
  .Model.ColWidths("Col1") = 100
  .Model.ColWidths("Col2") = 120
  ...
End With

...
' --- sql-string for vDbDataTableABC ---
Dim vStrSqlString As String = "SELECT A, B, C, D FROM Table"
...

With GridDataBound.Model.ColStyles("Col1")
  .CellType = GridCellTypeName.GridListControl
  .DataSource = vDbDataTableABC
  .DisplayMember = "A"
  .ValueMember = "B"
End With


It works but I've 3 questions to use it.

1.) How to use "Col1" as listbox, so I can choose only entries of the list?

2.) How to set the witdh of "Col1"

3.) How to get the value of column 'C', when I choose an entrie of the listbox?


Can you help me?

Best regards,
Frank

Neelakandan Kannan [Syncfusion]
Replied On January 22, 2015 01:43 AM

Hi Frank,

 

Thank you for your interest in Syncfusion products.

 

Query-1

How to use "Col1" as listbox, so I can choose only entries of the list?

If you want to set the Column 1 style as Combobox or any other listbox control, you can use CellType property. Please make use of below code,

 

Code Snippet:

Dim choiceList As StringCollection = New StringCollection
choiceList.Add(
"Item1")
choiceList.Add(
"Item2")
Me.gridDataBoundGrid1.Model.ColStyles(1).CellType GridCellTypeName.ComboBox
Me.gridDataBoundGrid1.Model.ColStyles(1).ChoiceList choiceList

 

Note:

If you want to set ListBox control to grid cell, you need to set celltype as control and assign that ListBox control to grid.

 

Code Snippet:

Dim listBox As ListBox = New ListBox
listBox.Items.Add(
"Item1")
listBox.Items.Add(
"Item2")
Me.gridDataBoundGrid1.Model.ColStyles(1).CellType GridCellTypeName.Control
Me.gridDataBoundGrid1.Model.ColStyles(1).Control listBox

 

Query-2

How to set the witdh of "Col1"

The reported scenario with “Changing the column width” can be achieved by handling QueryColWidth event. Using this event, you can set column width for particular column.

 

Code Snippet:

AddHandler Me.gridDataBoundGrid1.Model.QueryColWidth, AddressOf Me.Model_QueryColWidth

Private Sub Model_QueryColWidth(ByVal sender As ObjectByVal As GridRowColSizeEventArgs)
        
If (e.Index 1Then ‘Specify your needed column index
            e.Size 200
            
e.Handled = true
        End If
    End Sub

 

 

Query-3

How to get the value of column 'C', when I choose an entrie of the listbox?

If you want to get the particular column value when selecting the entry in listbox or combobox, you can use CurrentCellCloseDropDown event. Using this event , you can get currently selected value from dropdown list using SelectedValue property of renderer.

 

Code Snippet:

AddHandler Me.gridDataBoundGrid1.CurrentCellCloseDropDown, AddressOf Me.gridDataBoundGrid1_CurrentCellCloseDropDown


    Private Sub gridDataBoundGrid1_CurrentCellCloseDropDown(ByVal sender As ObjectByVal As Syncfusion.Windows.Forms.PopupClosedEventArgs)
        
If (TypeOf Me.gridDataBoundGrid1.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            Dim 
renderer As GridDropDownGridListControlCellRenderer = CType(Me.gridDataBoundGrid1.CurrentCell.Renderer,GridDropDownGridListControlCellRenderer)
            
Dim selectedValue As String = renderer.ListControlPart.SelectedValue.ToString
            MessageBox.Show(
Me.gridDataBoundGrid1.Model(Me.gridDataBoundGrid1.CurrentCell.RowIndex, (Me.gridDataBoundGrid1.CurrentCell.ColIndex + 2)).CellValue.ToString) ’specify your needed column index for particular column value
        
End If
    End Sub

 

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan


Attachment: Sample_GDBC_VB_d02e0fb4.zip

Frank Piplak
Replied On January 23, 2015 09:59 AM

Hi Frank,

 

Thank you for your interest in Syncfusion products.

 

Query-1

How to use "Col1" as listbox, so I can choose only entries of the list?

If you want to set the Column 1 style as Combobox or any other listbox control, you can use CellType property. Please make use of below code,

 

Code Snippet:

Dim choiceList As StringCollection = New StringCollection
choiceList.Add(
"Item1")
choiceList.Add(
"Item2")
Me.gridDataBoundGrid1.Model.ColStyles(1).CellType GridCellTypeName.ComboBox
Me.gridDataBoundGrid1.Model.ColStyles(1).ChoiceList choiceList

 

Note:

If you want to set ListBox control to grid cell, you need to set celltype as control and assign that ListBox control to grid.

 

Code Snippet:

Dim listBox As ListBox = New ListBox
listBox.Items.Add(
"Item1")
listBox.Items.Add(
"Item2")
Me.gridDataBoundGrid1.Model.ColStyles(1).CellType GridCellTypeName.Control
Me.gridDataBoundGrid1.Model.ColStyles(1).Control listBox

 

Query-2

How to set the witdh of "Col1"

The reported scenario with “Changing the column width” can be achieved by handling QueryColWidth event. Using this event, you can set column width for particular column.

 

Code Snippet:

AddHandler Me.gridDataBoundGrid1.Model.QueryColWidth, AddressOf Me.Model_QueryColWidth

Private Sub Model_QueryColWidth(ByVal sender As ObjectByVal As GridRowColSizeEventArgs)
        
If (e.Index 1Then ‘Specify your needed column index
            e.Size 200
            
e.Handled = true
        End If
    End Sub

 

 

Query-3

How to get the value of column 'C', when I choose an entrie of the listbox?

If you want to get the particular column value when selecting the entry in listbox or combobox, you can use CurrentCellCloseDropDown event. Using this event , you can get currently selected value from dropdown list using SelectedValue property of renderer.

 

Code Snippet:

AddHandler Me.gridDataBoundGrid1.CurrentCellCloseDropDown, AddressOf Me.gridDataBoundGrid1_CurrentCellCloseDropDown


    Private Sub gridDataBoundGrid1_CurrentCellCloseDropDown(ByVal sender As ObjectByVal As Syncfusion.Windows.Forms.PopupClosedEventArgs)
        
If (TypeOf Me.gridDataBoundGrid1.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            Dim 
renderer As GridDropDownGridListControlCellRenderer = CType(Me.gridDataBoundGrid1.CurrentCell.Renderer,GridDropDownGridListControlCellRenderer)
            
Dim selectedValue As String = renderer.ListControlPart.SelectedValue.ToString
            MessageBox.Show(
Me.gridDataBoundGrid1.Model(Me.gridDataBoundGrid1.CurrentCell.RowIndex, (Me.gridDataBoundGrid1.CurrentCell.ColIndex + 2)).CellValue.ToString) ’specify your needed column index for particular column value
        
End If
    End Sub

 

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan


Attachment: Sample_GDBC_VB_d02e0fb4.zip

Hello Neelakandan,

thanks for your response but not all problems solved.

Query-1 How to use "Col1" as listbox, so I can choose only entries of the list?
Your example works but the realy problem, that I can fill the cell with anything else is allways existing.


Query-2 How to set the witdh of "Col1"
My mistake, I mean the width of the column 'C' from the sub-grid of the listbox.

I see your example for query 3 and build the following:

Private Sub GridBProjekteStunden_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs) Handles GridBProjekteStunden.CurrentCellShowingDropDown
        If (TypeOf Me.GridBProjekteStunden.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            Dim renderer As GridDropDownGridListControlCellRenderer = CType(sender.CurrentCell.Renderer, GridDropDownGridListControlCellRenderer)
            ' --- with of the hole grid ---
            renderer.ListControlPart.Grid.Width = 200
            renderer.ListControlPart.Grid.HideCols(0) = True
            renderer.ListControlPart.Grid.HideCols(1) = True
            renderer.ListControlPart.Grid.ColWidths(2) = 200
            ...
        End If
    End Sub

But it works not so good, perhaps you've right solution for me.

Query-3 How to get the value of column 'C', when I choose an entrie of the listbox?
Your example get the value of column 'Col3' but I mean the column 'C' from the sub-grid of the listbox.
But it helps me to find a solution for my problem:

Private Sub GridBProjekteStunden_CurrentCellCloseDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.PopupClosedEventArgs) Handles GridBProjekteStunden.CurrentCellCloseDropDown
        If (TypeOf Me.GridBProjekteStunden.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            Dim renderer As GridDropDownGridListControlCellRenderer = CType(Me.GridBProjekteStunden.CurrentCell.Renderer, GridDropDownGridListControlCellRenderer)
           renderer.ListControlPart.SelectedItem.Row.ItemArray(3).ToString
        End If
    End Sub

It works, do you think it's ok? Then I think query 3 is solved

I hope for help, many thanks.

Best regards,
Frank

Attachment: GridDataBound_listbox_01_cbe388f2.zip

Neelakandan Kannan [Syncfusion]
Replied On January 26, 2015 02:51 AM

Hi Frank,

 

Thank you for your update.

 

Query-1

How to use "Col1" as listbox, so I can choose only entries of the list?

If you want to restrict the ComboBoxCell being edited, you can use CurrentCellKeyPress event. You can cancel KeyPress event by enabling Handled property.

 

Code Snippet:

AddHandler Me.gridDataBoundGrid1.CurrentCellKeyPress, AddressOf Me.gridDataBoundGrid1_CurrentCellKeyPress

Private Sub gridDataBoundGrid1_CurrentCellKeyPress(ByVal sender As ObjectByVal As KeyPressEventArgs)
        
If (TypeOf Me.gridDataBoundGrid1.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            
e.Handled = true
        End If
    End Sub

Query-2

How to set the width of "Col1"

The column width of the ComboBox dropdown container can be changed by using DefaultColWidth or Colwidths properties of Grid. DefaultColWidth property is used to set all the columns with same widths. Using ColWidths property, you can specify your needed columns to change width.

 

Code Snippet:

Private Sub gridDataBoundGrid1_CurrentCellShowedDropDown(ByVal sender As ObjectByVal As EventArgs)
        
If (TypeOf Me.gridDataBoundGrid1.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            Dim 
renderer As GridDropDownGridListControlCellRenderer = CType(Me.gridDataBoundGrid1.CurrentCell.Renderer,GridDropDownGridListControlCellRenderer)
            
'renderer.ListControlPart.Grid.DefaultColWidth = 100; //To Set all column widths as default
            
renderer.ListControlPart.Grid.ColWidths(1200
            
'To set particular column width                 
        
End If
    End Sub

Query-3

How to get the value of column 'C', when I choose an entrie of the listbox?

We analyzed your customization at our end. It seems that you are using Rows property to get items. But SelectedItem property does not contain any extension like Row. So that we need some more details regarding your customization. It would be more helpful if you provide any simple sample or you also modify our sample to reproduce.

 

Note:

If you have still an issue, please create Direct-Trac incident. It would be better follow up.

 

You can create the DT incident from the following link.

<http://www.syncfusion.com/account/dashboard>

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan


Attachment: ModifiedSample_GDBC_VB_93a8bca7.zip

Frank Piplak
Replied On January 31, 2015 12:47 PM

Hello Neelakandan,

many thanks for your example but I'm not contented with this solution, sorry.

Query-1
It's allways possible to insert anything with 'Ctr+C'

Query-2
It works not until the second dropdown done.

Regards,
Frank

Neelakandan Kannan [Syncfusion]
Replied On February 2, 2015 12:25 PM

Hi Frank,

 

Thank you for your update.

 

Query-1

It's allways possible to insert anything with 'Ctr+C'

The reported scenario can be resolved by handling CurrentCellKeyDown event. Please make use of below code,

 

Code Snippet:

 Private Sub gridDataBoundGrid1_CurrentCellKeyDown(ByVal sender As ObjectByVal As KeyEventArgs)
        
If (TypeOf Me.gridDataBoundGrid1.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            
e.Handled = true
        End If
    End Sub

 

Query-2

It works not until the second dropdown done.

 

The dropdown container size can be changed by using Size property of CurrentCellShowingDropDown event. Please make use of below code,

 

Code Snippet:

Private Sub gridDataBoundGrid1_CurrentCellShowingDropDown(ByVal sender As ObjectByVal As GridCurrentCellShowingDropDownEventArgs)
        
If (TypeOf Me.gridDataBoundGrid1.CurrentCell.Renderer Is GridDropDownGridListControlCellRenderer) Then
            Dim 
renderer As GridDropDownGridListControlCellRenderer = CType(Me.gridDataBoundGrid1.

CurrentCell.Renderer,GridDropDownGridListControlCellRenderer)
            e.Size 
= New Size((renderer.ListControlPart.Grid.Model.ColWidths.GetTotal(0

renderer.ListControlPart.Grid.Model.ColCount) + 200),

 renderer.ListControlPart.Grid.RowHeights.GetTotal(0, renderer.ListControlPart.Grid.Model.RowCount)) //Specify your needed size   
        
End If
    End Sub

 

Please let me know if you have any concerns.

 

Regards,

Neelakandan

 


Attachment: ModifiedSample_Drop_Down_size_6ec2ec9b.zip

Frank Piplak
Replied On February 3, 2015 01:36 PM

Hello Neelakandan,

works fine, many thanks.


Best regards,
Frank

Neelakandan Kannan [Syncfusion]
Replied On February 4, 2015 08:15 AM

Hi Frank,

Thank you for your update.

We are glad to hear from you that the scenario is resolved.

Please let us know if you need further assistance on this.

Regards,

Neelakandan



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;