I'm creating CRUD app, and basically what I want to do, is to create datagrid where each row have its own button to decrease the value of one cell (which is taking data from SQL by Entity Framework). Like code behind work with data base is working or i will fix this later, but my problem is exactly the way of showing the button in data grid.
Its shown like this: System.Windows.Controls.Button
. I don't know how to change this.
I was looking for this problem for about 3 hours and I was unable to find a satisfactory answer that would help me.
Part of class responsible for data-handling
public Button SubstractByOne = new Button();
public LearnDayAdvenced(LearningDays learnDay)
{
SubstractByOne.Name = "substract";
SubstractByOne.Click += new RoutedEventHandler(Button_click);
}
protected void Button_click(object sender, EventArgs e)
{
SubstractTime();
}
And the code responsible for displaying and creating data. (I know that I should refactor this but in case of problem its like this)
ICollection<LearnDayAdvenced> learnDayAdvenceds = new List<LearnDayAdvenced>();
foreach (var learningDay in learningDaysAsSource)
{
LearnDayAdvenced advencedLearnDay = new LearnDayAdvenced(learningDay);
learnDayAdvenceds.Add(advencedLearnDay);
}
DataTable learningDataTable = new DataTable("Learn Days");
learningDataTable.Columns.Add(new DataColumn("Subject name", typeof(string)));
learningDataTable.Columns.Add(new DataColumn("time left", typeof(double)));
learningDataTable.Columns.Add(new DataColumn("Substract by 1", typeof(Button)));
foreach (var learnDay in learnDayAdvenceds)
{
learningDataTable.Rows.Add(learnDay.LearnDay.subjectName, learnDay.LearnDay.learningTimeAmount, learnDay.SubstractByOne);
}
this.DataGrid.ItemsSource = learningDataTable.AsDataView();