I am fairly new to both C# and WPF, but the project I am working on seems to be a great fit for them. I have a dynamic grid of labels set up based off of a database. I need to set them up for drag and drop. I have some labels set up as header, and they are populated based off the next seven fridays. I made a function to pull the data from the database and compare each date to the content of the header label content. Then I make labels containing a job number and state for each of the dates that match with the header.
Kind of like this on load
content = Job# + " " + JobState
-Date+7n----Date+7n----Date+7n----Date+7n----Date+7n----Date+7n-----Date+7n
Content------Content-----Content-----Content-----Content-----Content------Content
Content------Content-----Content-----Content-----Content-----Content------Content
Content------Content-----Content--------------------Content-----Content------Content
Content---------------------Content--------------------Content-----Content------Content
Content---------------------Content--------------------Content---------------------Content
Pretty much when the date runs out of jobs it just doesn't make anymore labels for that column.
I tried to make it as dynamic and expandable as possible so I have a forward and backwards button that push all the dates up a week or back a week then repopulates the grid based off of the new date at the top.
private void AddLabel(ref int rowNum, string val, List<string>[] datGrid)
{
int rowLen;
int margin1;
int margin2;
var lb = new Label();
lb.HorizontalAlignment = HorizontalAlignment.Left;
lb.VerticalAlignment = VerticalAlignment.Top;
lb.Height = 32;
lb.Width = 155;
rowLen = datGrid[rowNum].Count;
lb.AllowDrop = true;
margin1 = 25 + (200 * (rowNum));
margin2 = 10 + (40 * (rowLen));
var gName = "grid" + (rowNum + 1) + (rowLen + 1);
lb.Margin = new Thickness(margin1, margin2, 0, 0);
lb.Content = val;
lb.Name = gName;
dyGrid.Children.Add(lb);
}
Where I put the row number that the label needs to be added to as rowNum, the actual content of the label as val and datGrid as the array of lists that holds the names for all the labels. I just can't figure out how to add a mouseDown or other drag and drop events to the labels as I make it.