Wpf 带文本框的二维动态列表视图
这是一个具有动态标题和行的动态listview。但这里的问题是,我尝试使用文本框作为Wpf 带文本框的二维动态列表视图,wpf,wpf-controls,wpfdatagrid,Wpf,Wpf Controls,Wpfdatagrid,这是一个具有动态标题和行的动态listview。但这里的问题是,我尝试使用文本框作为 xaml = "<DataTemplate><TextBox VerticalAlignment=\"Center\" TextChanged=\"{Binding " + propName + "}\" > " + propName + "</TextBox></DataTemplate>"; xaml=”“+propName+”; 在方法CreateDa
xaml = "<DataTemplate><TextBox VerticalAlignment=\"Center\" TextChanged=\"{Binding " + propName + "}\" > " + propName + "</TextBox></DataTemplate>";
xaml=”“+propName+”;
在方法CreateDataTemplate中不使用带有绑定的复选框,而是在单击btn后无法提取值
下面是带有复选框的代码。有人能帮我吗。我还需要文本框中的值。先谢谢你
<Window x:Class="WpfListView.SalesPerson_SalesRegion_Association"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="SalesPerson_SalesRegion_Association" Height="500" Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ListView Name="listView1" Width="400" Height="300" Margin="20" HorizontalAlignment="Left">
<ListView.View>
<GridView></GridView>
</ListView.View>
</ListView>
<Button Grid.Row="1" HorizontalAlignment="Left"
Content="ShowSelectedMapping"
Name="btnShow" Width="150" Margin="0,10,0,0" Click="btnShow_Click"></Button>
<TextBlock Name="textBlock1" Grid.Row="2"
HorizontalAlignment="Left" Margin="0,10,0,0"></TextBlock>
</Grid>
公共部分类SalesPerson\u SalesRegion\u关联:窗口
{
公共销售人员销售区域协会()
{
初始化组件();
AddColumnsToListView();
DataTable dt=DataHelper.GetRegionPersonAssociation();
listView1.ItemsSource=dt.DefaultView;
}
私有void btnShow\u单击(对象发送者,路由目标)
{
DataView视图=listView1.ItemsSource作为DataView;
DataTable userSelectionTbl=view.ToTable();
DataTable idTable=DataHelper.GetRegionIdPersonIdMatrix();
List lstRegion=SalesRegion.GetRegions();
string selectedRegion=string.Empty;
string msg=string.Empty;
DataRow dRow=null;
int totRows=userSelectionTbl.Rows.Count;
int totCols=lstreation.Count-1;
string strTempMsg=string.Empty;
bool isColChecked=false;
对于(int-rowIndex=0;rowIndex
}//DataHelper类
public class SalesPerson
{
public int SalesPersonId
{ get; set; }
public string SalesPersonName
{ get; set; }
public SalesPerson(int salesPersonId, string salesPersonName)
{
this.SalesPersonId = salesPersonId;
this.SalesPersonName = salesPersonName;
}
public static List<SalesPerson> GetSalesPersons()
{
List<SalesPerson> lst = new List<SalesPerson>();
lst.Add(new SalesPerson(101, "SalesPerson1"));
lst.Add(new SalesPerson(201, "SalesPerson2"));
lst.Add(new SalesPerson(301, "SalesPerson3"));
lst.Add(new SalesPerson(401, "SalesPerson4"));
lst.Add(new SalesPerson(501, "SalesPerson5"));
return lst;
}
} // class SalesPerson ends here
public class SalesRegion
{
public int RegionId
{ get; set; }
public string RegionName
{ get; set; }
public SalesRegion(int regionId, string regionName)
{
this.RegionId = regionId;
this.RegionName = regionName;
}
public static List<SalesRegion> GetRegions()
{
List<SalesRegion> lst = new List<SalesRegion>();
lst.Add(new SalesRegion(501,"North"));
lst.Add(new SalesRegion(502, "South"));
lst.Add(new SalesRegion(503, "East"));
lst.Add(new SalesRegion(504, "West"));
lst.Add(new SalesRegion(505, "MyRegion"));
return lst;
}
} // class SalesRegion ends here
public class DataHelper
{
public static DataTable GetRegionPersonAssociation()
{
DataTable dt = new DataTable();
//Create data table structure
// SalesPerson Region1 Region2 Region3 ....
DataColumn colSalesPerson = new DataColumn("SalesPersonName", typeof(string));
dt.Columns.Add(colSalesPerson);
List<SalesRegion> lstRegions = SalesRegion.GetRegions();
DataColumn colRegion = null;
foreach (SalesRegion region in lstRegions)
{
colRegion = new DataColumn(region.RegionName, typeof(bool));
dt.Columns.Add(colRegion);
}
//Fill data into the data table
List<SalesPerson> personList = SalesPerson.GetSalesPersons();
DataRow dRow = null;
foreach (SalesPerson sp in personList)
{
dRow = dt.NewRow();
dRow["SalesPersonName"] = sp.SalesPersonName;
foreach (SalesRegion sr in lstRegions)
{
dRow[sr.RegionName] = false;
}
dt.Rows.Add(dRow);
}
return dt;
}
public static DataTable GetRegionIdPersonIdMatrix()
{
DataTable dt = new DataTable();
//Create data table structure
// SalesPerson Region1 Region2 Region3 ....
DataColumn colSalesPerson = new DataColumn("SalesPersonId", typeof(int));
dt.Columns.Add(colSalesPerson);
List<SalesRegion> lstRegions = SalesRegion.GetRegions();
DataColumn colRegion = null;
foreach (SalesRegion region in lstRegions)
{
colRegion = new DataColumn(region.RegionName, typeof(int));
dt.Columns.Add(colRegion);
}
//Fill data into the data table
List<SalesPerson> personList = SalesPerson.GetSalesPersons();
DataRow dRow = null;
foreach (SalesPerson sp in personList)
{
dRow = dt.NewRow();
dRow["SalesPersonId"] = sp.SalesPersonId;
foreach (SalesRegion sr in lstRegions)
{
dRow[sr.RegionName] = sr.RegionId;
}
dt.Rows.Add(dRow);
}
return dt;
} } // class DataHelper ends here
公共类销售人员
{
公共int销售员
{get;set;}
公共字符串salersonname
{get;set;}
公共销售人员(int salersonid、字符串salersonname)
{
this.salersonid=salersonid;
this.salersonname=salersonname;
}
公共静态列表GetSalespers()
{
List lst=新列表();
1.增加(新销售人员(101名,“销售人员1”);
1.增加(新销售人员(201,“销售人员2”);
第一次添加(新销售人员(301,“销售人员3”);
1.增加(新销售人员(401,“销售人员4”);
1.增加(新销售人员(501,“销售人员5”);
返回lst;
}
}//班级销售人员到此结束
公共类销售区域
{
公共区域ID
{get;set;}
公共字符串RegionName
{get;set;}
public SalesRegion(int regionId,string regionName)
{
this.RegionId=RegionId;
this.RegionName=RegionName;
}
公共静态列表GetRegions()
{
List lst=新列表();
第一次添加(新销售区域(501,“北部”);
第一次添加(新销售区域(502,“南”);
第一次添加(新销售区域(503,“东部”);
一级添加(新销售区域(504,“西部”);
第一次添加(新销售区域(505,“MyRegion”);
返回lst;
}
}//SalesRegion类在此结束
公共类DataHelper
{
公共静态数据表GetRegionPersonAssociation()
{
DataTable dt=新的DataTable();
//创建数据表结构
//萨尔
public class SalesPerson
{
public int SalesPersonId
{ get; set; }
public string SalesPersonName
{ get; set; }
public SalesPerson(int salesPersonId, string salesPersonName)
{
this.SalesPersonId = salesPersonId;
this.SalesPersonName = salesPersonName;
}
public static List<SalesPerson> GetSalesPersons()
{
List<SalesPerson> lst = new List<SalesPerson>();
lst.Add(new SalesPerson(101, "SalesPerson1"));
lst.Add(new SalesPerson(201, "SalesPerson2"));
lst.Add(new SalesPerson(301, "SalesPerson3"));
lst.Add(new SalesPerson(401, "SalesPerson4"));
lst.Add(new SalesPerson(501, "SalesPerson5"));
return lst;
}
} // class SalesPerson ends here
public class SalesRegion
{
public int RegionId
{ get; set; }
public string RegionName
{ get; set; }
public SalesRegion(int regionId, string regionName)
{
this.RegionId = regionId;
this.RegionName = regionName;
}
public static List<SalesRegion> GetRegions()
{
List<SalesRegion> lst = new List<SalesRegion>();
lst.Add(new SalesRegion(501,"North"));
lst.Add(new SalesRegion(502, "South"));
lst.Add(new SalesRegion(503, "East"));
lst.Add(new SalesRegion(504, "West"));
lst.Add(new SalesRegion(505, "MyRegion"));
return lst;
}
} // class SalesRegion ends here
public class DataHelper
{
public static DataTable GetRegionPersonAssociation()
{
DataTable dt = new DataTable();
//Create data table structure
// SalesPerson Region1 Region2 Region3 ....
DataColumn colSalesPerson = new DataColumn("SalesPersonName", typeof(string));
dt.Columns.Add(colSalesPerson);
List<SalesRegion> lstRegions = SalesRegion.GetRegions();
DataColumn colRegion = null;
foreach (SalesRegion region in lstRegions)
{
colRegion = new DataColumn(region.RegionName, typeof(bool));
dt.Columns.Add(colRegion);
}
//Fill data into the data table
List<SalesPerson> personList = SalesPerson.GetSalesPersons();
DataRow dRow = null;
foreach (SalesPerson sp in personList)
{
dRow = dt.NewRow();
dRow["SalesPersonName"] = sp.SalesPersonName;
foreach (SalesRegion sr in lstRegions)
{
dRow[sr.RegionName] = false;
}
dt.Rows.Add(dRow);
}
return dt;
}
public static DataTable GetRegionIdPersonIdMatrix()
{
DataTable dt = new DataTable();
//Create data table structure
// SalesPerson Region1 Region2 Region3 ....
DataColumn colSalesPerson = new DataColumn("SalesPersonId", typeof(int));
dt.Columns.Add(colSalesPerson);
List<SalesRegion> lstRegions = SalesRegion.GetRegions();
DataColumn colRegion = null;
foreach (SalesRegion region in lstRegions)
{
colRegion = new DataColumn(region.RegionName, typeof(int));
dt.Columns.Add(colRegion);
}
//Fill data into the data table
List<SalesPerson> personList = SalesPerson.GetSalesPersons();
DataRow dRow = null;
foreach (SalesPerson sp in personList)
{
dRow = dt.NewRow();
dRow["SalesPersonId"] = sp.SalesPersonId;
foreach (SalesRegion sr in lstRegions)
{
dRow[sr.RegionName] = sr.RegionId;
}
dt.Rows.Add(dRow);
}
return dt;
} } // class DataHelper ends here
xaml = "<DataTemplate><TextBox VerticalAlignment=\"Center\" Tag=\"{Binding " + propName + ", Mode=TwoWay}\" > " + propName + "</TextBox></DataTemplate>";
<Style TargetType="{x:Type TextBox}">
<EventSetter Event="TextChanged" Handler="TextBox_TextChanged"></EventSetter>
</Style>
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
(sender as TextBox).Tag = true;
}