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

Change Column Item to Combobox

9 Answers 426 Views
GridView
This is a migrated thread and some comments may be shown as answers.
willi
Top achievements
Rank 1
willi asked on 10 Mar 2009, 10:19 AM
Hi!
I'm trying to change a standart column to a combobox Column.
My way is to remove the original column with:
RadGridSubstances.Columns.Remove(RadGridSubstances.Columns("uzs_PosNeg")) 

and add a new GridViewComboBoxColumn with:
Dim comboBoxColumn As New GridViewComboBoxColumn 
comboBoxColumn.HeaderText = "positiv/negativ" 
comboBoxColumn.FieldName = "uzs_PosNeg" 
comboBoxColumn.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList 
 
 ' Create Custom Table for Combobox 
Dim comboDT As New DataTable 
comboDT.Columns.Add("Name"GetType(System.String)) 
comboDT.Columns.Add("Wert"GetType(System.Int16)) 
Dim myNewRow As DataRow = comboDT.NewRow() 
myNewRow("Name") = "positiv" 
myNewRow("Wert") = 1 
comboDT.Rows.Add(myNewRow) 
Dim myNewRow2 As DataRow = comboDT.NewRow() 
myNewRow2("Name") = "negativ" 
myNewRow2("Wert") = 0 
comboDT.Rows.Add(myNewRow2) 
 
comboBoxColumn.DataSource = comboDT 
comboBoxColumn.ValueMember = "Wert" 
comboBoxColumn.DisplayMember = "Name" 
comboBoxColumn.FieldName = "uzs_PosNeg" 
RadGridSubstances.Columns.Add(comboBoxColumn) 

At least I have two columns one with the Headertext "uzs_PosNeg" and one with the Headertext "positiv/negativ" (the ComboBoxColumn) When I change the Value in the Combobox (and change the row)  - the value in the other column changes and the Combobox displays nothing.

How could I do this? Is there an easyer way to assign two values to the combobox instead of creating a Datatable?

regards
Willi

9 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 16 Mar 2009, 12:13 PM
Hello willi,

Please note that you should not remove the standard column in order to use a GridViewComboBoxColumn. The standard column should be kept in RadGridView and the GridViewComboBoxColumn should point to the data field of the standard column by the FieldName property. The standard column is the column that actually holds the values. If you want to hide the standard column, you can just set is IsVisible property to false.

I am demonstrating a sample project demonstrating the approach. If you have additional questions, feel free to contact me.

Greetings,
Nikolay
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
willi
Top achievements
Rank 1
answered on 17 Mar 2009, 12:53 PM
Thank you!

There's just one tiny problem. My Integer Column from the SQL-Database is a Decimal Column in the RadGrid. So my Combocolumn won't work.
How can I Change this column to a INT16 Column?
I tried:
RadGridSubstances.Columns("uzs_PosNeg").DataType = GetType(System.Int32)but
but this won't work.

regards
Willi
0
Nikolay
Telerik team
answered on 18 Mar 2009, 02:57 PM
Hi willi,

Thank you for getting back to me.

Please note that we have only one column type for all 'number' data columns - GridViewDecimalColumn. We do not have a special class called GridViewIntegerColumn. However, GridViewDecimalColumn, as I mentioned, covers all the 'number' data columns and its DataType depends on the type of the data column. Since the DataType is automatically generated from the type of the data column, you cannot change it.

Could you please share with us more details of the issue that you will have in the scenario of GridViewDecimalColumn and GridViewComboBoxColumn? I am not sure I understood you quite correctly, so any additional information will be of help.

Kind regards,
Nikolay
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
willi
Top achievements
Rank 1
answered on 19 Mar 2009, 08:41 AM
This is the Problem: DemoVideo

And this is how I load a Table from a Database and assign it to the grid:
Public Sub loadSubstanceList(ByVal unt_id As Guid) 
            log.Debug(unt_id.ToString) 
            RadGridSubstances.DataSource = Nothing 
            RadGridSubstances.Columns.Clear() 
 
            Dim SQLDef As SqlCommand = SQLFunctions.initSQLDef 
            Dim SQLWhere As String 
 
            If unt_id = Nothing Then 
                SQLWhere = " and  0 = 1 " 
            Else 
                SQLWhere = " and unt_id = @unt_id " 
                SQLDef.Parameters.AddWithValue("unt_id", unt_id) 
            End If 
 
            SQLDef.CommandText = "select uzs_id, sub_Name Substanz, " & _ 
                                "isnull(ltrim(str(sub_UntererGw,10,1)) + '-' + ltrim(str(sub_OBererGw,10,1)) + ' ' + sub_einheit,'') OTB, " & _ 
                                "uzs_Chromatogramm, uzs_wert, uzs_PosNeg, sub_isWert, " & _ 
                                "sub_UntererGw, sub_ObererGw  " & _ 
                                "from UntersuchungZuSubstanz " & _ 
                                "left outer join substanzen on UntersuchungZuSubstanz.sub_id = substanzen.sub_id " & _ 
                                "where UntersuchungZuSubstanz.deletedWhen is null " & SQLWhere & _ 
                                "order by substanzen.sub_Name" 
            Dim dt As DataTable = SQLFunctions.getTable(SQLDef) 
 
 
            RadGridSubstances.DataSource = dt 
 
            ' Oberfläche einstellen  
            With RadGridSubstances 
                .Columns("Substanz").ReadOnly = True 
                .Columns("uzs_id").IsVisible = False 
                .Columns("sub_isWert").IsVisible = False 
                .Columns("uzs_wert").HeaderText = "Wert" 
 
                .Columns("sub_UntererGw").IsVisible = False 
                .Columns("sub_ObererGw").IsVisible = False 
                .Columns("uzs_Chromatogramm").HeaderText = "Chromatogramm" 
                .Columns("OTB").ReadOnly = True 
            End With 
       
            Dim comboBoxColumn As New GridViewComboBoxColumn 
            comboBoxColumn.HeaderText = "positiv/negativ" 
            comboBoxColumn.FieldName = "uzs_PosNeg" 
            comboBoxColumn.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList 
 
            ' Tabelle für Combobox erstellen 
            Dim comboDT As New DataTable 
            comboDT.Columns.Add("Name"GetType(System.String)) 
            comboDT.Columns.Add("Wert"GetType(System.Int16)) 
            Dim myNewRow As DataRow = comboDT.NewRow() 
            myNewRow("Name") = "positiv" 
            myNewRow("Wert") = 1 
            comboDT.Rows.Add(myNewRow) 
            Dim myNewRow2 As DataRow = comboDT.NewRow() 
            myNewRow2("Name") = "negativ" 
            myNewRow2("Wert") = 0 
            comboDT.Rows.Add(myNewRow2) 
 
            RadGridSubstances.Columns("uzs_PosNeg").IsVisible = False 
 
            comboBoxColumn.DataSource = comboDT 
            comboBoxColumn.ValueMember = "Wert" 
            comboBoxColumn.DisplayMember = "Name" 
            comboBoxColumn.FieldName = "uzs_PosNeg" 
            RadGridSubstances.Columns.Add(comboBoxColumn) 
 
            RadGridSubstances.MasterGridViewTemplate.BestFitColumns() 
        End Sub 

The uzs_PosNeg is a Integer Column

When I change one line of code from your Example from

original: gridDT.Columns.Add("uzs_PosNeg", GetType(System.Int16))
to
modified: gridDT.Columns.Add("uzs_PosNeg", GetType(System.Decimal))

I have the same effect (Video Link)

Thanks in advance for your help

regards
willi

0
Nikolay
Telerik team
answered on 20 Mar 2009, 03:40 PM
Hello willi,

Thank you for getting back to me.

I now understand your issue. When the DataType of your GridViewDecimalColumn is Decimal and your GridViewComboBoxColumn's ValueMember column type is Int16, the selected values are not persisted.

However, if the DataType of the GridViewDecimalColumn is Decimal and the type of the value member column is Decimal, you should not have such issues. I am attaching a sample project to demonstrate this.

As you will notice, we are referring to the column "Price" which is of type Decimal. Our data column for the GridViewComboBoxColumn is of type Decimal as well. On my side, the values are persisted using this approach. If you continue to experience the issue, please open a new support ticket and send me a sample project to demonstrates it. This will allow me to investigate the case further.

All the best,
Nikolay
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
willi
Top achievements
Rank 1
answered on 25 Mar 2009, 12:51 PM
Hi!

Here is an Example with the Problem as an vb.net Project.  (Originally the Database is on a SQL Server).

Regards
Willi
0
Nikolay
Telerik team
answered on 26 Mar 2009, 04:28 PM

Hello willi,

Thank you for the sample project.

It helped me to reproduce the issue. We will investigate what is causing it in order to address it in one of our next releases. For the time being, please set the FieldSize of the uzs_PosNeg data column to Decimal. This resolves the issue in your sample project.

I am updating your Telerik points for the report. If you have additional questions, feel free to contact me.

Regards,

Nikolay
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
willi
Top achievements
Rank 1
answered on 27 Mar 2009, 08:42 AM
Solution (Workaround)!
In the Query I cast the Integer Column as Decimal Column:

uzs_wert,cast (uzs_PosNeg as Decimal(10,2)) as uzs_PosNeg
0
Nikolay
Telerik team
answered on 30 Mar 2009, 01:19 PM
Hi willi,

Thank you for sharing your workaround with the community.

Best wishes,
Nikolay
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
willi
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
willi
Top achievements
Rank 1
Share this question
or