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

Populating choices into ComboBox

5 Answers 320 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Claude asked on 21 Aug 2012, 08:08 PM
I have a grid with column6 being a combobox.   Using Q212 c#.  I want to programmatically load vaules into the combobox during form load.  I cannot seem to find a method to do this.  I see examples when one is creating the column on the fly, but my columns are already defined.  Also how do select a default value to show in the combobox. 

I also want to have another column in the same grid to be a calculation based on other cells in the same row.   How do I go about that?


Why won't this code fill a gridview that has 4 decimal controls?

decimal[] row31 = new decimal[] { 1, 120, 1000, 100 };

decimal[] row32 = new decimal[] { 2, 120, 1000, 100 };

decimal[] row33 = new decimal[] { 3, 120, 1000, 100 };

object[] rows3 = new object[] { row31, row32, row33 };

foreach (decimal[] rowArray in rows3)

{

radGridView1.Rows.Add(rowArray);

}



Thanks in advance.


5 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 24 Aug 2012, 10:31 AM
Hi Claude,

Thank you for writing.

GridViewComboBox column has a DataSource property where you can assign the desired source. This way all cells in this column will use this data source. A sample is available here: http://www.telerik.com/help/winforms/gridview-columns-gridviewcomboboxcolumn.html.

On the other hand if you want to change the data source of the editor, you can do that by using the CellEditorInitialized event. Note that you should have a data source that contains all values in the column, which should be assigned to the DataSource property of GridViewComboBoxColumn. You can use the following code snippet:
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    if (e.Column.Name == "YourComboBoxColumn")
    {
        RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
        RadDropDownListEditorElement element = editor.EditorElement as RadDropDownListEditorElement;
        element.DataSource = yourDataSource;
    }
}

Regarding column calculation, you can use expression column. You can read more about that in the online documentation.

I hope that you find this information useful.

Regards,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Claude
Top achievements
Rank 1
answered on 04 Sep 2012, 03:14 PM
I am still having issues. I wish to populate the following values into the combobox in index 6. This column is already created during design time.
new string [] {"Sine", "Square", "Sawtooth", "User Definded"};

The online example shows GridViewComboBoxColumn, but that is not available.

I have been trying to use DataGridViewComboBoxColumn
0
Svett
Telerik team
answered on 06 Sep 2012, 11:29 AM
Hi Claude,

If you want to define the data source of the GridViewComboBoxColumn programmatically, you should use the following code snippet:
GridViewComboBoxColumn comboBoxColumn = this.radGridView1.Columns[0] as GridViewComboBoxColumn;
comboBoxColumn.DataSource = new string[] { "Sine", "Square", "Sawtooth", "User Defined" };

You should not use DataGridViewComboBoxColumn. This type is used by the Microsoft DataGridView.

Greetings,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Claude
Top achievements
Rank 1
answered on 06 Sep 2012, 04:54 PM
I am using the latest version of winforms and it does not allow the use of  GridViewComboBoxColumn  - States there is a refernce missing, but Telerik.WinControls.GridView is referenced.
0
Stefan
Telerik team
answered on 07 Sep 2012, 05:51 AM
Hi Claude,

The column at hand is located at the following namespace:
Telerik.WinControls.UI

I hope this helps.
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Answers by
Svett
Telerik team
Claude
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or