<DataGrID RowheaderWIDth="0" ItemsSource="{Binding PartsList,UpdateSourceTrigger=PropertyChanged}" autoGenerateColumns="False"> <DataGrID.Columns> <DataGrIDTextColumn header="Item name" IsReadonly="True" WIDth="*" Binding="{Binding Productname}"></DataGrIDTextColumn> <DataGrIDTextColumn header="Model name" IsReadonly="True" WIDth="*" Binding="{Binding CarModelname}"></DataGrIDTextColumn> <DataGrIDTextColumn header="Company name" IsReadonly="True" WIDth="*" Binding="{Binding Companname}"></DataGrIDTextColumn> <DataGrIDTextColumn header="Price" IsReadonly="True" WIDth="*" Binding="{Binding Rate}"> </DataGrID.Columns></DataGrID>
这里PartsList是实体Part的ObservableCollection.
现在我想将自定义列添加到显示折扣的DataGrID和显示净金额的另一列.我怎样才能做到这一点?
请提出一个好主意,因为我需要处理成千上万的记录,因此性能对我来说非常重要.
先感谢您.
解决方法 尝试在DataGrID的Loaded事件上添加列:private voID DataGrID_Loaded_1(object sender,RoutedEventArgs e){ dataGrID.Columns.Add((DataGrIDTextColumn)this.Resources["discountColumn"]); dataGrID.Columns.Add((DataGrIDTextColumn)this.Resources["NetAmountColumn"]); //Alternatively you can create columns in .cs like dataGrID.Columns.Add(new DataGrIDTextColumn() { header = "Dicount",Binding = new Binding("discount") }); dataGrID.Columns.Add(new DataGrIDTextColumn() { header = "Net Amount",Binding = new Binding("NetAmount") });}
<Window.Resources> <DataGrIDTextColumn x:Key="discountColumn" header="discount" IsReadonly="True" WIDth="*" Binding="{Binding discount}"/> <DataGrIDTextColumn x:Key="NetAmountColumn" header="Net Amount" IsReadonly="True" WIDth="*" Binding="{Binding NetAmount}"/></Window.Resources><DataGrID RowheaderWIDth="0" x:name="dataGrID" Loaded="DataGrID_Loaded_1" />总结
以上是内存溢出为你收集整理的c# – 与自定义列绑定的WPF数据网格全部内容,希望文章能够帮你解决c# – 与自定义列绑定的WPF数据网格所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)