WFP DataGrid with Dynamic Columns and Rows and how to bind them to XAML without fixed properties

  • Thread starter Thread starter labjac
  • Start date Start date
L

labjac

Guest
Hallo

I hope somebody can assist with some guidance on the below:

Our Data in SQl looks as below:

The PigeonLocation consist of the following information: 01 - area ID, 01- Zone Position, 01 - Row and 01 is the Column. (01010101) as per red arrow below. This can grow to many columns or Rows depending on the setup. Each of these cells will then be populated by the OrderAllocation.

1610615.jpg

Previously we used a Windows Form DataGridView with a manipulated DataTable to suit the above requirement. (Output as per below).

1610620.jpg

public class ActiveWallViewModel
{
public DataTable GetActiveWall()
{
var locationsFromSql = new tb_ProdPigeonStatusSql();
var dt = new DataTable("Data From SQL");
var wallTemplate = new DataTable("New Empty Wall ");
var wallPopulated = new DataTable();
var dg = new DataGridView();
int maxRows = 0;
int maxCol = 0;
int maxZones = 0;

dt = locationsFromSql.SelectAllRecords();

maxRows = GetMaxWithParameters.GetMaxNumber(dt, 4, 2, 3);
maxCol = GetMaxWithParameters.GetMaxNumber(dt,6, 2, 3);
maxZones = GetMaxWithParameters.GetMaxNumber(dt, 2, 2, 3);
// Get max Columns and rows

wallTemplate = WallConfigurators.Logic.TableMatrix.CreateSetTableMatrix("New Empty Wall", maxCol, maxRows);
wallPopulated = PopulateWallWithOrders(wallTemplate, dt);
dg.DataSource = wallPopulated;

return wallPopulated;
}

public DataTable PopulateWallWithOrders(DataTable EmptyWall, DataTable TableData)
{
var populatedWall = new DataTable();
var dg = new DataGridView();
populatedWall = EmptyWall;
int rowCounter = 0;
string pigeonLocation = "";
int currentRow = 0;
int currentColumn = 0;

foreach(DataRow dr in TableData.Rows)
{
pigeonLocation = (TableData.Rows[rowCounter][3]).ToString();
currentRow = (Convert.ToInt32(pigeonLocation.Substring(4, 2))-1);
currentColumn = Convert.ToInt32(pigeonLocation.Substring(6, 2));

if (TableData.Rows[rowCounter][7].ToString().Length != 0)
{
populatedWall.Rows[currentRow][currentColumn] = TableData.Rows[rowCounter][7].ToString();
}
else
{
populatedWall.Rows[currentRow][currentColumn] = 0;
}
rowCounter++;
}
populatedWall.TableName = "Populated Wall";
return populatedWall;
}
}
}





We starting using WPF and the databinding on the datagrid is something I cannot get my head around, the issue is the Row and Columns cannot be fixed, so trying to create a modelview object with fixed Records is going to be a issue.

creating a class as below is not going to work, because there could be undefined amount of both.

public class PigeonLocations
{
public int PigeonRow {get; set}
public int PigeonColumns {get; set;}
}

Second issue is to Bind these Headers to the Path=xxx for the Properties, because this can change.

Hope somebody can just give us some guidelines, our data is correct in a datatable, just need to find a way to use databinding on the WPF XAML that is not fixed to a property?




labjac

Continue reading...
 
Back
Top