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

How to Not Display GridViewMultiComboBoxColumn Column

3 Answers 316 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hector
Top achievements
Rank 1
Hector asked on 29 Jul 2011, 03:55 PM

I've recently taken over development of a WinForms application using VB.NET.

A form has a RADGridView control (rgvEntities) consisting of the following Columns collection members:
- EntityName: GridViewMultiComboBoxColumn
- City: GridViewTextBoxColumn
- State: GridViewTextboxColumn
- Flag: GridViewCheckBoxColumn
- EntityID: GridViewTextBoxColumn

When the user clicks on the grid view row labelled "Click here to add a new row", the EntityName column displays a combobox for the user to choose the EntityName. When the user clicks on the drop-down arrow of the combobox, the combobox displays the following columns entityid, entityname, city, state.

My issue is that I'd like for the entityid column to not be displayed.

The RADGridView control (rgvEntities) is populated with the following code, that receives the reader as an argument:

  Dim dr As DataRow
  Dim strValues(5) As String

  While reader.Read
    strValues(0) = reader("EntityID")
    strValues(1) = reader("City")
    strValues(2) = reader("State")
    If reader("Flag") = "Y" Then
 strValues(3) = True
    Else
 strValues(3) = False
    End If
    strValues(4) = reader("EntityId")

    rgvEntities.Rows.Add(strValues)
  End While

I think (remember, I didn't code this initially) the entityName column is populated with the following VB.NET code in the Handles rgvEntities.UserAddedRow event handler:

  Dim colEntity As Telerik.WinControls.UI.GridViewComboBoxColumn

  Dim dbconn As New SqlConnection(App.My.Settings.dbConn)
  Dim cmd As New SqlCommand
  Dim daEntity As SqlDataAdapter
  cmd.CommandType = CommandType.Text
  cmd.Connection = dbconn

  Dim sSql As String = ""
  sSql = "select entityid, entityname, city, state from Entities "
  sSql = sSql & " where Entityid > 0 order by 1"
  cmd.CommandText = sSql
  daEntity = New SqlDataAdapter(cmd)
  ds = New DataSet()
  daEntity.Fill(ds)

  colEntity = rgvEntities.Columns("Entity")
  colEntity.DataSource = ds.Tables(0)
  colEntity.DisplayMember = "entityname"
  colEntity.ValueMember = "entityid"

  dbconn.Close()
  colEntity = Nothing
  daEntity = Nothing
  dbconn = Nothing

Where rgvEntities is the RADGridView defined as:
  Friend WithEvents rgvEntities As Telerik.WinControls.UI.RadGridView

Thanks in advance for any help.

3 Answers, 1 is accepted

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

Thank you for writing.

If I understand correctly, you would like to hide a column in RadGridView. If this is the case, please note, that each column in RadGridView has its IsVisible property, which determines whether the column should be visible in the control.

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 >>
0
Hector
Top achievements
Rank 1
answered on 03 Aug 2011, 04:05 PM

Stefan,

I'm sorry, but I may not have made myself completely clear. I have a RADGridView control (rgvEntities), which has a GridViewMultiComboBoxColumn. In the Visual Studio designer, the GridViewDataColumn Collection Editor has the 'Entity' column defined as GridViewMultiComboBoxColumn.

 I think (remember, I didn't originally design this) the GridViewMultiComboBoxColumn is populated with the following excerpted code:

 

' note, ironically, not defined as GridViewMultiComboBoxColumn
Dim colEntity As Telerik.WinControls.UI.GridViewComboBoxColumn
sSql = "select entityid, entity, city, state from entity "
sSql = sSql & " WHERE Entityid > 0 order by 1"
cmd.CommandText = sSql
daEntity = New SqlDataAdapter(cmd)
ds = New DataSet()
daEntity.Fill(ds)
colEntity = rgvEntities.Columns("Entity")
colEntity.DataSource = ds.Tables(0)
colEntity.DisplayMember = "entity"
colEntity.ValueMember = "entityid"

I don't want to see the "entityid" column from the above query in the GridViewMultiComboBoxColumn within the RADGridView.

Note, the following code snippet Handles the UserAddedRow on the GridView:

<BR>
    Private Sub rgvEntities_UserAddedRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewRowEventArgs) Handles rgvEntities.UserAddedRow
        Try
            Dim colEntity As Telerik.WinControls.UI.GridViewComboBoxColumn
            Dim viewEntity As DataView
            colEntity = rgvEntities.Columns("Entity")
            viewEntity = New DataView(CType(colEntity.DataSource, DataTable))
            viewEntity.RowFilter = "entityid=" + e.Row.Cells("Entity").Value.ToString
            If viewEntity.Count <> 0 Then
                e.Row.Cells("city").Value = viewEntity(0).Row("city")
                e.Row.Cells("state").Value = viewEntity(0).Row("state")
                e.Row.Cells("EntityID").Value = viewEntity(0).Row("entityid")
            End If
        Catch ex As Exception
            MessageBox.Show("rgvEntities_UserAddedRow : " + ex.Message)
        End Try
    End Sub

Thanks in advance,

Hector

0
Accepted
Stefan
Telerik team
answered on 04 Aug 2011, 04:18 PM
Hi Hector,

Thank you for the clarification.

You are talking about hiding a column in GridViewMultiComboBoxColumn. On the other hand, the code that you pasted uses GridViewComboBoxColumn and this gets me a little confused. However, the only column that might contain columns is the first one mentioned and this is why I will suggest how to hide a column from  GridViewMultiComboBoxColumn. To do that, subscribe to the CellEditorInitialized event and there you can access the ActiveEditor, which is RadMultiColumnComboBoxElement. Using it, you can access the columns of GridViewMultiComboBoxColumn and you can hide the "entityid" column. Here is the code snippet for that:
Private Sub rgvEntities_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles rgvEntities.CellEditorInitialized
       Dim editor As RadMultiColumnComboBoxElement = CType(rgvEntities.ActiveEditor, RadMultiColumnComboBoxElement)
       If editor IsNot Nothing Then
           editor.Columns("entityid").IsVisible = False
       End If
   End Sub

I hope that this is what you needed. Let me know if you have any other questions.
 
All the best,
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