This is a migrated thread and some comments may be shown as answers.

Can Width of Drop-Down Listbox Be Changed for GridViewMultiComboBoxColumn within a GridView?

3 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hector
Top achievements
Rank 1
Hector asked on 10 Aug 2011, 05:19 PM

I have a GridViewMultiComboBoxColumn (width: 175) within a GridView (width: 500). The GridViewMultiComboBoxColumn's DataSource is set to the result of a query selecting several columns (id, name, city, state). The GridViewMultiComboBoxColumn dislays multiple columns when the user clicks on the drop-down arrow. Since the GridViewMultiComboBoxColumn is made up of several columns (id, name, city, state), when the drop-down arrow is clicked on, and the listbox drops down, the column width of the GridViewMultiComboBoxColumn (175) is rather narrow and its hard to see the information contained in the columns.

Is it possible to change the width, currently 175, of the listbox that drops down for a GridViewMultiComboBoxColumn contained within a GridView, yet keep the width of the column (175) within the GridView without changing? If so, can you show me with code.

In other words, can I keep the control's width at 175, before and after the user clicks the drop-down arrow, but make it much wider, when they click on the drop-down arrow and the drop-down portion (or listbox aspect) of the GridViewMultiComboBoxColumn is accessible?

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 11 Aug 2011, 02:09 PM
Hi Hector,

Thank you for writing.

You can achieve the desired functionality by handling the CellEditorInitialized event, where you can gain access to RadMultiColumnComboBoxElement. Once you get the element, set the GridViewMultiComboBoxColumn column's width and subscribe to the PopupOpening event of the column. In the event handler set the desired size for the popup and the grid control accordingly. Please refer to the attachment for a sample implementation.

I hope the provided information addresses your question. Should you have any other questions, do not hesitate to contact us.
 
All the best,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Hector
Top achievements
Rank 1
answered on 12 Aug 2011, 07:55 PM

Stefan,

That did the trick, with a little conversion to VB.NET :-) . I'm not sure if this is the right place to add a follow-up question. Please, let me know if I should start a new thread, but . . .

Now that it's much more user friendly, the next thing I'd like to do is to auto-populate the city and state of the GridView columns, when the user selects a row in the  GridViewMultiComboBoxColumn contained within the GridView (rgv).

Note, at present, the way this is working is that the event handler for the GridView's UserAddedRow event (rgv_UserAddedRow) is updating the values, but this occurs after the row is added. So what happens is that the user may enter values for City and State, and they get overridden.

For example, the user selects Name1, City1, State1 from the GridViewMultiComboBoxColumn, then enters City2, State2 in the GridView, presses tab or down arrow, and the row's city and state values are reset to City1, State1.

Present Code:


Friend WithEvents rgv As Telerik.WinControls.UI.RadGridView
  
Private Sub rgv_UserAddedRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewRowEventArgs) Handles rgv.UserAddedRow
  Dim col As Telerik.WinControls.UI.GridViewMultiComboBoxColumn
  Dim vw As DataView
  col = rgv.Columns("Name")
  vw = New DataView(CType(col.DataSource, DataTable))
  vw.RowFilter = "id=" + e.Row.Cells("Name").Value.ToString
  If vw.Count <> 0 Then
     e.Row.Cells("city").Value = vw(0).Row("city")
     e.Row.Cells("state").Value = vw(0).Row("state")
     e.Row.Cells("id").Value = vw(0).Row("id")
  End If
End Sub

At present I am also handling the rgv.CellEditorInitialized in rgv_CellEditorInitialized event to set the  GridViewMultiComboBoxColumn 'id' column's IsVisible property to False, and set the column's widths with the following code:

Private Sub rgv_CellEditorInitialized(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles rgv.CellEditorInitialized
  Dim editor As tlrk.RadMultiColumnComboBoxElement = CType(rgv.ActiveEditor, tlrk.RadMultiColumnComboBoxElement)
  If editor IsNot Nothing AndAlso editor.Columns IsNot Nothing AndAlso _
     editor.Columns("id") IsNot Nothing AndAlso _
     editor.Columns("name") IsNot Nothing AndAlso _
     editor.Columns("city") IsNot Nothing Then
  
     RemoveHandler editor.PopupOpening, AddressOf PopUpOpening
     AddHandler editor.PopupOpening, AddressOf PopUpOpening
  
     editor.Columns("id").IsVisible = False
     editor.Columns("name").Width = 200
     editor.Columns("city").Width = 100
  End If
End Sub
  
Private Sub PopUpOpening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
  If TypeOf sender Is tlrk.RadMultiColumnComboBoxElement Then
     Dim editor As tlrk.RadMultiColumnComboBoxElement = TryCast(sender, tlrk.RadMultiColumnComboBoxElement)
     editor.MultiColumnPopupForm.MinimumSize = New Size(400, 100)
     editor.EditorControl.GridViewElement.MinSize = New Size(400, 100)
  End If
End Sub

Thanks in advance,

WinFormsRadControlsNewbie  :)

0
Stefan
Telerik team
answered on 15 Aug 2011, 04:44 PM
Hello Hector,

Thank you for your reply.

In regards to your first questions, usually it is good to separate the different topics in different threads in order to make our forums easier to use - finding the information that you need faster (by a descriptive title) and reading not very long threads concerning only the topic mentioned in the title.

However, you can overcome the behavior with the overridden data by checking if the value of the row is empty and only in this case populate it with information from the GridViewMultiComboBoxColumn, otherwise keep the user data:
If vw.Count <> 0 Then
            If e.Row.Cells("city").Value Is Nothing Then
                e.Row.Cells("city").Value = vw(0).Row("city")
            End If
 
            If e.Row.Cells("state").Value Is Nothing Then
                e.Row.Cells("state").Value = vw(0).Row("state")
            End If
 
            If e.Row.Cells("id").Value Is Nothing Then
                e.Row.Cells("id").Value = vw(0).Row("id")
            End If
        End If

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
 
Kind regards,
Stefan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
GridView
Asked by
Hector
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Hector
Top achievements
Rank 1
Share this question
or