Okay, this one is s doosy from what I can tell..
I have a database which stores data as PK pointers to other tables (good ol relational data storage... yay...) Seems simple enough right?
Well I have a need to output the information from that table to a DataGrid object, and am trying to figure out how to convert the values on the fly...
Here's some code to look over. When I export the table to an excel sheet, I use this converter to get the value of the pointed to data...
public static async Task<string> GetChamber(int pk)
{
//ChambersRepository().GetRecordByID is a call to a Sql qurery that returns the row data from the table with the human relatable name in it
var value = await new ChambersRepository().GetRecordByID(pk).ConfigureAwait(true);
return value?.Cmbr ?? "NA";
}
Hence when in my reporting code where I dump the data to the excel sheet I use this
else if (lbl.Equals("Chamber"))
{
worksheet.Range[rowID, n].Text = await ReloadingLookup.GetChamber(rldata.Chamber).ConfigureAwait(false);
}
This all works just good and fine, but when it comes to making the display to let the user select which records they want to export to the excel sheet. I have the following problem
var colChamber = new GridTextColumn
{
MappingName = "Chamber",
HeaderText = "Chamber",
HeaderFontAttribute = FontAttributes.Bold,
HeaderCellTextSize = 14,
CellTextSize = 12,
};
At first I thought, no worries, I can use a converter and a display binding something like this
var binding = new Binding("Path=Chamber")
{
Converter = new FillImageFromBytes(),
ConverterParameter="Chamber",
};
var colChamber = new GridTextColumn
{
MappingName = "Chamber",
HeaderText = "Chamber",
HeaderFontAttribute = FontAttributes.Bold,
HeaderCellTextSize = 14,
CellTextSize = 12,
DisplayBinding = binding,
};
The problem is that IValueConverter is not thread safe and I both don't want to and should not block the UI thread while the data looks up...
I am considering making a mock table in memory and executing a series of Joins and such, but would like to see if there is any other idea of how I can try to use my existing process of calling my GetChamber(pk)
routine.
My other alternative is to re-engineer the table, and how it stores it data, but I think it would be easier, and less painful to give a Tiger a vasectomy with no anesthesia...
While we are all here I have a question 2 which may be a lot easier to answer (still need the first one answered though
)
When working with a datagrid, I want to give the user a button to "Select All" so that they don't have to click every record in the table.
I assume this is just a matter of poking DataGrid.SelectedItems
but what is the easiest way to go about it?
Thanks for any help! I know I'm probably boned here, but I hope someone can see something I missed...
Cheers!