Hello Szymon,
Thank you for contacting Telerik Support.
In order to achieve your goal, please, have a look at the following approach:
List<
string
> names =
new
List<
string
>();
public
Form1()
{
InitializeComponent();
List<MyName> objects =
new
List<MyName>()
{
new
MyName(
"John Smith"
),
new
MyName(
"Peter Jackson"
),
new
MyName(
"Merry Stones"
),
new
MyName(
"Bryan Cold"
),
};
names.AddRange(GetNames(objects));
this
.radGridView1.AutoGenerateColumns =
false
;
GridViewTextBoxColumn textBoxColumn =
new
GridViewTextBoxColumn(
"Name"
);
radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
GridViewComboBoxColumn comboCol =
new
GridViewComboBoxColumn(
"Ref Name"
);
comboCol.DataSource = names;
this
.radGridView1.Columns.Add(comboCol);
this
.radGridView1.DataSource = objects;
this
.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
}
private
void
radGridView1_CellEditorInitialized(
object
sender, GridViewCellEventArgs e)
{
RadDropDownListEditor editor = e.ActiveEditor
as
RadDropDownListEditor;
if
(e.RowIndex > -1 && editor !=
null
)
{
editor.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
(editor.EditorElement
as
RadDropDownListEditorElement).DataSource =
FilterList((editor.EditorElement
as
RadDropDownListEditorElement).DataSource, (e.Row.DataBoundItem
as
MyName).Name);
}
}
private
object
FilterList(
object
dataSource,
string
filterName)
{
List<
string
> dataNames =
new
List<
string
>();
foreach
(
string
name
in
dataSource
as
List<
string
>)
{
if
(name != filterName)
{
dataNames.Add(name);
}
}
return
dataNames;
}
private
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.RowIndex > -1 && e.Column.Name ==
"Ref Name"
)
{
(e.CellElement
as
GridComboBoxCellElement).Text = (e.Row.DataBoundItem
as
MyName).Name;
}
}
private
IEnumerable<
string
> GetNames(List<MyName> objects)
{
List<
string
> objectNames =
new
List<
string
>();
foreach
(MyName nameObj
in
objects)
{
objectNames.Add(nameObj.Name);
}
return
objectNames;
}
public
class
MyName
{
public
string
Name {
get
;
set
; }
public
MyName(
string
name)
{
this
.Name = name;
}
}
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application.
Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>