15 Answers, 1 is accepted

You cannot add a windows forms DataGridView cell to the RadGridView, but if you want to create a GridViewComboBoxColumn for the RadGridView dynamically, you can take a look at the following help article.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

but I could not find any solution for My Problem
I want ot dynamically add data into combobox in telerik gridview cells
Can you help me a little more about it?
thanks in advance

Do you want just to add a GridViewComboBoxColumn to the grid with a set of value, or do you need a specific set of values for each row based on a condition? If you need the latter, please take a look at this thread.
If you just want a normal column with a data source please take a loot at this example:
using
System;
using
System.ComponentModel;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
public
partial
class
Form1 : Form
{
private
RadGridView radGridView1;
public
Form1()
{
InitializeComponent();
this
.Controls.Add(radGridView1 =
new
RadGridView());
this
.radGridView1.DataBindingComplete +=
new
GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete);
radGridView1.Dock = DockStyle.Fill;
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.DataSource =
new
ProductsCollection(1000);
}
void
radGridView1_DataBindingComplete(
object
sender, GridViewBindingCompleteEventArgs e)
{
radGridView1.Columns[
"BuyerId"
].IsVisible =
false
;
var column =
new
GridViewComboBoxColumn(
"SomeComboboxColumn"
,
"SomeComboboxColumn"
);
column.DataSource =
new
BuyersCollection(10, 10);
column.ValueMember =
"Id"
;
column.FieldName =
"BuyerId"
;
column.DisplayMember =
"Name"
;
this
.radGridView1.Columns.Add(column);
this
.radGridView1.BestFitColumns();
}
}
#region Helpers
public
class
Product : INotifyPropertyChanged
{
private
int
id, buyerId;
public
int
BuyerId
{
get
{
return
buyerId; }
set
{
buyerId = value;
OnPropertyChanged(
"BuyerId"
);
}
}
public
int
Id
{
get
{
return
id; }
set
{
id = value;
OnPropertyChanged(
"Id"
);
}
}
public
Product(
int
id,
int
buyerId)
{
this
.Id = id;
this
.BuyerId = buyerId;
}
private
void
OnPropertyChanged(
string
propertyName)
{
if
(PropertyChanged !=
null
)
{
PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
public
event
PropertyChangedEventHandler PropertyChanged;
}
public
class
Buyer
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
Buyer(
int
id,
string
name)
{
this
.Id = id;
this
.Name = name;
}
}
public
class
ProductsCollection : BindingList<Product>
{
public
ProductsCollection(
int
noItems)
{
for
(
int
i = 0; i < noItems; i++)
{
this
.Add(
new
Product(i, i + 10));
}
}
}
public
class
BuyersCollection : BindingList<Buyer>
{
public
BuyersCollection(
int
startIndex,
int
lenght)
{
for
(
int
i = 0; i < 10; i++)
{
this
.Add(
new
Buyer(i + 10,
"Buyer"
+ (i + 1)));
}
}
}
#endregion Helpers
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

I want to have comboboxColumn but The the cells can have different values (In your code we only can have equal values)
I want to bind different ArrayList Objects (for example) to the ComboBox Cell for each different row
I couldn't find out how to do that from the thread you mentioned.
In .NET datagridview I used this code to do that
public
void
displayDGV(DataGridView DGV, ArrayList list,
string
strColumnName,
string
strHeader)
{
DGV.Columns.Add(strColumnName, strHeader);
DataGridViewComboBoxCell cmbcell =
new
DataGridViewComboBoxCell();
if
(list !=
null
&& list.Count != 0)
{
for
(
int
j = 0; j < list.Count; j++)
{
cmbcell.Items.Add((
string
)list[j]);
}
cmbcell.Value = list[0];
}
DGV[strColumnName, m] = cmbcell;
}
Thank you for the question.
In order to achieve the desired behavior, you should bind the combo column to one data source and bind the editor of the column to certain parts of the main data source. This is demonstrated in the attached sample project.
I hope this helps.
Best wishes,
Nikolay
the Telerik team

for each row (each record), I have different values that may not have any common data but in your code all rows have the same values
for instance, I have a column named "Phones". each record has different number of values for that column like below:
ID col1 col2 col3 Phones
1 first1 first2 first3 001,002,003 (comboboxCell)
2 sec2 sec2 sec3 004,005,006 (comboboxCell)
3 third1 third2 third3 007,010 (comboboxCell)
4 four1 four2 four3 008,000 (comboboxCell)
how can I bind an arraylist of data to each telerik comboboxCell? (DataGridViewRadComboBoxCell)

In my reply with the example , i have also provided a link where you can find a solution if you want differend data sources / row.
You can handle that like i said here, or using the CellEditorInitialized event, like Alexander said, something like this:
void
radGridView1_CellEditorInitialized(
object
sender, GridViewCellEventArgs e)
{
if
(e.Column.Name ==
"SomeComboboxColumn"
)
{
var dropDownEditor = radGridView1.ActiveEditor
as
RadDropDownListEditor;
var dropDownEditorElement = dropDownEditor.EditorElement
as
RadDropDownListEditorElement;
var buyers =
new
BuyersCollection(e.RowIndex, e.RowIndex + 2);
dropDownEditorElement.DataSource = buyers;
dropDownEditorElement.DisplayMember =
"Name"
;
dropDownEditorElement.ValueMember =
"Id"
;
}
}
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

Thank you for answer
but can you use these codes in a simple c# project.
I could not use it correctly
I will be appreciated you if you do that.
thanks again

There was a C# project attached in this thread by Nikolay. See above.
Hope that helps
Richard

Of course i can, please take a look at the following example:
using
System;
using
System.ComponentModel;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
public
partial
class
Form1 : Form
{
private
RadGridView radGridView1;
public
Form1()
{
InitializeComponent();
this
.Controls.Add(radGridView1 =
new
RadGridView());
radGridView1.Dock = DockStyle.Fill;
radGridView1.CellEditorInitialized +=
new
GridViewCellEventHandler(radGridView1_CellEditorInitialized);
this
.radGridView1.DataBindingComplete +=
new
GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete);
}
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.DataSource =
new
ProductsCollection(10);
}
void
radGridView1_CellEditorInitialized(
object
sender, GridViewCellEventArgs e)
{
if
(e.Column.Name ==
"SomeComboboxColumn"
)
{
var dropDownEditor = radGridView1.ActiveEditor
as
RadDropDownListEditor;
var dropDownEditorElement = dropDownEditor.EditorElement
as
RadDropDownListEditorElement;
var buyers =
new
BuyersCollection(Convert.ToInt32(e.Value));
dropDownEditorElement.DataSource = buyers;
dropDownEditorElement.DisplayMember =
"Name"
;
dropDownEditorElement.ValueMember =
"Id"
;
}
}
void
radGridView1_DataBindingComplete(
object
sender, GridViewBindingCompleteEventArgs e)
{
radGridView1.Columns[
"BuyerId"
].IsVisible =
false
;
var column =
new
GridViewComboBoxColumn(
"SomeComboboxColumn"
,
"SomeComboboxColumn"
);
column.DataSource =
new
BuyersCollection(10);
column.ValueMember =
"Id"
;
column.FieldName =
"BuyerId"
;
column.DisplayMember =
"Name"
;
this
.radGridView1.Columns.Add(column);
this
.radGridView1.BestFitColumns();
}
}
#region Helpers
public
class
Product
{
public
int
Id
{
get
;
set
;
}
public
int
BuyerId
{
get
;
set
;
}
public
Product()
{
}
public
Product(
int
id,
int
buyerId)
{
this
.Id = id;
this
.BuyerId = buyerId;
}
}
public
class
Buyer
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
Buyer(
int
id,
string
name)
{
this
.Id = id;
this
.Name = name;
}
}
public
class
ProductsCollection : BindingList<Product>
{
public
ProductsCollection(
int
noItems)
{
for
(
int
i = 0; i < noItems; i++)
{
this
.Add(
new
Product(i, i + 10));
}
}
}
public
class
BuyersCollection : BindingList<Buyer>
{
public
BuyersCollection(
int
startIndex)
{
for
(
int
i = startIndex; i < startIndex + 10; i++)
{
this
.Add(
new
Buyer(i,
"Buyer "
+ (i + 1).ToString()));
}
}
}
#endregion Helpers
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

it works
thank you very much

Hi,
I have a similar problem as the original poster. The code in the last post from Emanuel Varga almost solve the issue, but it does not solve populating the grid with existing data. Try to change the input to the BuyersCollection() constructor in radGridView1_DataBindingComplet():
From:
column.DataSource =
new
BuyersCollection(10);
To:
column.DataSource =
new
BuyersCollection(5);
The result is that the last five rows show empty values in the "SomeComboboxColumn". I assume this is because the list currently bound to this column does not contain the missing values.
So the remaining question is: How do I populate a grid when one column contain values from many different (dynamic) lists?
Regards,
K
You get the described empty rows, because changing the code to "column.DataSource = new BuyersCollection(5)" leaves some column values without a pair in its data source.
In order to allow for showing the right text in the combo-box column, all of its values should be presented in its data source.
All the best,
Martin Vasilev
the Telerik team

I know the cell becomes empty because it's value is not present in the data source. That's what I wanted to demonstrate by the code change.
My problem was when the grid was initially populated with data. In that case the CellEditorInitialized was not yet called, and hence the datasource was empty.
I found a different approach to this issue in another thread, which use the CellBeginEdit and CellFormatting events. So far it seems to work fine.
Regards,
K
I am glad you have found a solution in the given forum thread. Do not hesitate to contact us again if you have any other questions.
All the best,
Martin Vasilev
the Telerik team