Thanks for your help.
I could manage adding the CheckBox and convert my code to work with SfDataGrid and loop through the grid.
But, I cannot select each CheckBox row by row. The only way I can select my CheckBox is select the Header Checkbox. So, it would be all selected or none selected at all.
I've attached an image so you could see how it shows in SfDataGrid.
So, here's the code.
The OnLoad Form Event load the DataSource from DataTable and adds new Column to SfDataGrid.
DataTable dt = new DataTable();
data.DataSource = BindSource();
//If I remove this, the DataGrid cannot load dt.Columns.Add("Sel", typeof(bool));
data.Columns.Add(new GridCheckBoxColumn()
{
MappingName = "Sel",
HeaderText = "Sel",
AllowThreeState = false,
AllowText = true,
AllowCheckBoxOnHeader = true
});
dt.Columns.Add("Sel", typeof(bool));
Then, with your help, I can loop trrough the rows to check which Rows are Checked (Sel = true) and Ordem has Value and update my database:
var ctx = new DbContext();
var records = data.View.Records;
foreach (var record in records)
{
var dataRowView = record.Data as DataRowView;
if (dataRowView != null)
{
var selected = dataRowView.Row["Sel"];
if (selected.GetType() != typeof(DBNull) && (bool)selected)
{
try
{
var Ordem = dataRowView.Row["Ordem"];
int ID = Convert.ToInt32(dataRowView.Row["AvariaPID"]);
var query = ctx.tblStuff.FirstOrDefault(c => c.PID == ID);
if (ChkAtualizar.Checked & DataDe.Value != null) //This are 1 CheckBox and 1 DateTime outside DataGrid
{
query.Ordem = Ordem.ToString().Trim();
query.DataDefinitiva = DataDe.Value;
query.Estado = "Definitiva";
query.UpdatedBy = UserInfo.CurrentLoggedUser;
query.UpdatedOn = DateTime.Now;
}
So, this is working, but I need to select each Row 1 by one and not all or nothing!
Can you point me in right direction?
Thanks.
EDIT: Weel, I forgot to give Edit permission for the Sel Column since I locked my DataGrid to Edit. Now it works.
Thanks.