I'm trying to add a CheckedComboBoxEdit
to a GridView
using WinForms
and devexpress
. This is what I got for now:
using (var _db = new DB())
{
var isemirleri = _db.IsEmris.AsQueryable();
var oalist = _db.OperasyonAksakliks.AsQueryable();
gcIsEmirleri.DataSource =
(from i in isemirleri
select new {
ID = i.isEmriId,
İşEmriNo = i.isEmriNo,
Aksaklık = string.Join(",",
oalist
.Where(o => o.operasyonId == i.Operasyons.FirstOrDefault().operasyonId)
.Select(o => o.Durus.durusAdi).ToList())
}).ToList();
gvIsEmirleri.BeginUpdate();
//------------------------ THIS LINE -------------------------------------\\
//DataColumn col = new DataColumn("Aksaklık", typeof(string));
//------------------------ THIS LINE -------------------------------------\\
GridColumn column = gvIsEmirleri.Columns["Aksaklık"];
column.Caption = "Aksaklık";
column.Name = "Aksaklık";
gvIsEmirleri.EndUpdate();
RepositoryItemCheckedComboBoxEdit chk= new RepositoryItemCheckedComboBoxEdit();
chk.Items.Clear();
foreach (Durus d in _db.Durus.Where(q => q.aksaklikMi == true))
chk.Items.Add(new ListItem(d.durusId, d.durusAdi));
chk.EditValueChanged += new EventHandler(chk_EditValueChanged);
gvIsEmirleri.Columns["Aksaklık"].ColumnEdit = chk;
}
It successfully shows the present Operasyons
with commas between and CheckedComboBoxEdit
s can be seen on the grid (it shows the small button at the right of the cell).
However, the list of elements don't show up when I click on the cell. I debugged the project and observed that chk
is set up correctly and holds the Items
as meant to be.
If I de-comment the line I marked as THIS LINE
and don't add Aksaklık
to gcIsEmirleri.DataSource
it successfully adds the list and it can be used properly, I can add the checked elements to the related database table, but I cannot see the changes in the view. By that I mean I cannot see the selected elements, as string combined or as checked in the line.
What am I doing wrong or what can I do else to make it work?
The column Aksaklık
must be created once. Adding a new GridColumn
and assigning DataSource
causes the program not to work properly.
So I created a new column while assigning DataSource
, named TempColumn
, set it's visible to false. After that I added the GridColumn
and do the operations as in the code in the question. After that I used UnboundType
and get the needed string from TempColumn
:
column.UnboundType = DevExpress.Data.UnboundColumnType.String;
column.UnboundExpression = "[TempColumn]";