I have a list view with multiple cells that has been populated using grid view. I want to add a text box and button to each row dynamically. How can i do it?
My try:
public void PopulateCalibrationParam(IList<A2LCharacteristic> CalibrationParam)
{
int rowcount = 0;
CalibrationGrid.RowDefinitions.Clear();
CalibrationGrid.ColumnDefinitions.Clear();
RowDefinition rd = new RowDefinition();
rd.Height = new GridLength();
CalibrationGrid.RowDefinitions.Add(rd);
CalibrationGrid.RowDefinitions.Add(new RowDefinition());
CalibrationGrid.ColumnDefinitions.Add(new ColumnDefinition());
Label t1 = new Label();
t1.Content = "Calibration Variables";
Grid.SetColumn(t1, 0);
Grid.SetRow(t1, rowcount);
CalibrationGrid.Children.Add(t1);
ListView l1 = new ListView();
GridView g1 = new GridView();
g1.AllowsColumnReorder = true;
GridViewColumn g2 = new GridViewColumn();
g2.Header = "Name";
g2.Width = 200;
g2.DisplayMemberBinding = new Binding("Name");
g1.Columns.Add(g2);
GridViewColumn g5 = new GridViewColumn();
g5.Header = "DataType";
g5.Width = 200;
g5.DisplayMemberBinding = new Binding("DataType");
g1.Columns.Add(g5);
GridViewColumn g3 = new GridViewColumn();
g3.Header = "Value";
g3.Width = 200;
g3.DisplayMemberBinding = new Binding("Value");
g1.Columns.Add(g3);
GridViewColumn g4 = new GridViewColumn();
g4.Header = "Action";
g4.Width = 200;
g4.DisplayMemberBinding = new Binding("ToDo");
g1.Columns.Add(g4);
l1.View = g1;
Grid.SetRow(l1, rowcount + 1);
CalibrationGrid.Children.Add(l1);
for (int i = 0; i < CalibrationParam.Count; i++)
{
Label lb1 = new Label();
lb1.Content = CalibrationParam[i].Name;
Label lb2 = new Label();
lb2.Name = CalibrationParam[i].RecordLayoutRef.Parameters[0].DataType.ToString();
DataTemplate dd = new DataTemplate();
TextBox tb = new TextBox();
Button b1 = new Button();
b1.Content = "OK";
b1.Height = 30;
b1.Width = 150;
l1.Items.Add(new User() { Name = lb1.Content, DataType = lb2.Name, Value = tb, ToDo = b1 });
}
}
public class User
{
public object Name { get; set; }
public string DataType { get; set; }
public Control Value
{
get;
set;
}
public Control ToDo { get; set; }
}
I am getting :
I want text box and button in column 3 and column 4.
Please help. I found a similar problem but cannot able to solve. Please help.

CellTemplateof theGridViewColumnas a TextBox