i'm working on a project at a company for school and I have to make a datagrid with ticketinformation: The id-number, description of a ticket.
In my Tickettable in the database, I have a column 'Item' and it can have the values: "Not to be invoiced","To be invoiced" or "Offer". The 3rd column in the datagrid has to be a checkboxcolumn and my boss wants me that there is a possibility to check the checkbox, that means the ticket has to be invoiced, and when I uncheck, it means "not to be invoiced" or "offer", that doesn't really matter. My problem is when I bind the "ID" and "Description"-fields, I don't know how to bind the checkboxcolumn with a 'true or false' field? I only know how to bind tablefields from Ticket, but I want to add a boolean-field so I can determine in code when it's "to be invoiced", my boolean-field has to be true and when it's not to be invoiced, it has to be false, so unchecked.
dgTickets.DataContext = new List<ISSUE>();
dgTickets.Columns.Add(new DataGridTextColumn { Header = "Id", Binding = new Binding("IM_ISSUE_NO") });
dgTickets.Columns.Add(new DataGridTextColumn { Header = "Description", Binding = new Binding("IM_DESCRIPTION") });
DataGridCheckBoxColumn chk = new DataGridCheckBoxColumn();
chk.Header = "To be invoiced?";
List<ISSUE> lTickets = new List<ISSUE>();
lTickets = _ISSUEBO.getTickets();
//here I want to make a list of booleans when the tickets are 'to be invoiced or not' in the database
List<bool> lChecks = new List<bool>();
int intTeller = 0;
bool boolFact = false;
foreach (ISSUE i in lTickets) {
switch (i.IM_ITEM_CODE) {
case "TO BE INVOICED":
boolFact = true;
break;
case "NOT TB INVOICED":
boolFact = false;
break;
case "OFFER":
boolFact = false;
break;
default: break;
}
lChecks.Add(boolFact);
intTeller++;
}
Binding b = new Binding("lChecks"); //??? this is probably wrong, but i don't know how to do
chk.Binding = b;
this.dgTickets.Columns.Add(chk);
dgTickets.ItemsSource = lTickets;
Can anyone help me please?
Thanks in advance