Hello,
in a grid, I want to show a generic list of objects (type: Cars). No problem. One of the columns should be a ComboBox. In the combobox the selection should be based on a different class (type: Country). The name of country should be displayed in the grid. In both classes, there is a property ID of type GUID. The ID will be created automatically and have no setter.
Here is my class model
I have found no example for this purpose. For help, I would be grateful.
Christian Rudat
in a grid, I want to show a generic list of objects (type: Cars). No problem. One of the columns should be a ComboBox. In the combobox the selection should be based on a different class (type: Country). The name of country should be displayed in the grid. In both classes, there is a property ID of type GUID. The ID will be created automatically and have no setter.
using
System;
using
Telerik.WinControls.UI;
using
System.Linq;
namespace
Grid_Test
{
public
partial
class
frmMitarbeiterlister : Telerik.WinControls.UI.RadRibbonForm
{
private
TestData.Task taskNewBefore =
null
;
private
TestData.Task taskNewAfter =
null
;
public
frmMitarbeiterlister()
{
InitializeComponent();
}
private
void
GetTestData()
{
TestData.TestDataGenerator.GenerateTestData(1000);
gridMitarbeiterListe.DataSource = TestData.DataAccessLayer.EmployeeList;
gridMitarbeiterListe.BestFitColumns();
}
private
void
btnTestdatenErstellen_Click(
object
sender, EventArgs e)
{
GetTestData();
}
private
void
frmMitarbeiterlister_Load(
object
sender, EventArgs e)
{
GetTestData();
GetComboBox();
}
private
void
GetComboBox()
{
GridViewComboBoxColumn cbTask =
new
GridViewComboBoxColumn();
cbTask.UniqueName =
"TaskNew"
;
cbTask.HeaderText =
"New Task"
;
cbTask.DataSource = TestData.DataAccessLayer.TaskCatalog;
cbTask.ValueMember =
"ID"
;
cbTask.DisplayMember =
"Description"
;
cbTask.FieldName =
"TaskNew.ID"
;
// Name in the employee-class
gridMitarbeiterListe.MasterTemplate.Columns.Add(cbTask);
// problem: After leaving the row the new value disapear.
}
}
}
Here is my class model
using
System;
using
System.Collections.Generic;
using
System.Linq;
namespace
Grid_Test.TestData
{
internal
static
class
DataAccessLayer
{
internal
static
List<Employee> employeeList =
new
List<Employee>();
internal
static
List<Task> taskCatalog =
new
List<Task>();
public
static
List<Employee> EmployeeList
{
get
{
if
(employeeList ==
null
) { employeeList =
new
List<Employee>(); }
return
employeeList;
}
}
public
static
List<Task> TaskCatalog
{
get
{
if
(taskCatalog ==
null
)
{ taskCatalog =
new
List<Task>(); }
return
taskCatalog;
}
}
}
}
internal
class
Employee
{
internal
Employee() { }
private
Guid id = Guid.NewGuid();
private
string
firstname;
private
string
lastname;
private
DateTime birthDay;
private
Task taskOld;
private
Task taskNew;
public
Guid ID {
get
{
return
id; } }
public
string
Firstname {
get
{
return
firstname; }
set
{ firstname = value; } }
public
string
Lastname {
get
{
return
lastname; }
set
{ lastname = value; } }
public
DateTime BirthDay {
get
{
return
birthDay; }
set
{ birthDay = value; } }
public
Task TaskOld {
get
{
return
taskOld; }
set
{ taskOld = value; } }
public
Task TaskNew {
get
{
return
taskNew; }
set
{ taskNew = value; } }
}
internal
class
Task
{
internal
Task() { }
private
Guid id = Guid.NewGuid();
private
string
description;
public
Guid ID {
get
{
return
id; } }
public
string
Description {
get
{
return
description; }
set
{ description = value; } }
public
override
string
ToString()
{
return
Description;
}
}
I have found no example for this purpose. For help, I would be grateful.
Christian Rudat