关于datagridcolumnTextColumn的数据绑定

Silverlight3系列(五)数据绑定 Data Binding 2_小组_ThinkSAAS
Silverlight3系列(五)数据绑定 Data Binding 2
Silverlight3系列(五)数据绑定 Data Binding 2
接着上面一篇,我们来讨论绑定集合等。
  首先看一下可以进行绑定集合的控件属性,暂时我就不翻译了,因为翻译不好,还不如读英文呢。
Description
ItemsSource
Points to the collection that has all the objects that will be shown in the list.
DisplayMemberPath
Identifies the property that will be used to creat the display text for each item.
ItemTemplate
Providers a data template that will be used to create the visual appearance of each item.This property acts as a far more powerful replacement for DisplayMemberPath.
ItemsPanel
Providers a template that will be used to create the layout container that holds all the items in the list.
  这里你可能会想,什么类型的集合可以绑定到ItemsSource属性呢?告诉你,只需要实现IEnumerable就可以,但是,实现这个借口的集合是只读的。如果你想编辑这个集合,例如允许插入和删除,你需要更多的工作,后面我们会介绍。
  显示并且编辑集合项
  首先定义个数据库交互契约
&!--&br/ /&&br/ /&Code highlighting produced by Actipro CodeHighlighter (freeware)&br/ /&/&br/ /&&br/ /&--&
using System.Collections.G
using System.L
using System.T
using System.ServiceM
using System.Runtime.S
namespace Domain.Entity
[DataContract]
public class Customer : INotifyPropertyChanged
private int _intCustomerId;
private string _strCustomerN
private string _strCustomerC
private CustomerType
_CustomerT
private int _intCustomerTypeId;
[DataMember ]
public virtual
int CustomerTypeId
get { return _intCustomerTypeId; }
set { _intCustomerTypeId = }
[DataMember ]
public virtual
CustomerType
CustomerType
get { return this._CustomerT }
this._CustomerType =
OnPropertyChanged("CustomerType");
[DataMember]
public virtual int CustomerId
get { return this._intCustomerId; }
this._intCustomerId =
OnPropertyChanged("CustomerId");
[DataMember]
public virtual string CustomerName
get { return this._strCustomerN }
this._strCustomerName = OnPropertyChanged("CustomerName");
[DataMember]
public virtual string CustomerCode
get { return _strCustomerC }
this._strCustomerCode =
OnPropertyChanged("CustomerCode");
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyC
#endregion
private void OnPropertyChanged(string propertyName)
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  wcf定义接口
&!--&br/ /&&br/ /&Code highlighting produced by Actipro CodeHighlighter (freeware)&br/ /&/&br/ /&&br/ /&--&using S
using System.Collections.G
using System.Collections.ObjectM
using System.L
using System.Runtime.S
using System.ServiceM
using System.T
using Domain.E
namespace WcfService
[ServiceContract]
public interface IServiceCustomer
[OperationContract]
Domain.Entity.Customer GetCustomer(int customerId);
[OperationContract]
IList&Domain.Entity.Customer& GetAll();
[OperationContract]
void Add(Domain.Entity.Customer customer);
[OperationContract]
string SayHello(SysUser sysUser);
  实现这个接口
&!--&br/ /&&br/ /&Code highlighting produced by Actipro CodeHighlighter (freeware)&br/ /&/&br/ /&&br/ /&--&using S
using System.L
using System.Runtime.S
using System.ServiceM
using System.ServiceModel.A
using System.Collections.G
using System.Collections.ObjectM
using System.T
using System.Data.SqlC
using System.D
using Domain.E
using Common.C
using Common.D
namespace WcfService
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceCustomer : IServiceCustomer
private CustomerDAO _customerD
Common.Core.Utility.NHibernateUtility _NHU
MyValidator _myV
public ServiceCustomer()
_NHUtility = new Common.Core.Utility.NHibernateUtility();
_customerDao = new CustomerDAO(_NHUtility.GetSession());
// Add more operations here and mark them with [OperationContract]
#region IServiceCustomer Members
public Domain.Entity.Customer GetCustomer( int customerId)
Domain.Entity.Customer objCustomer = new Domain.Entity.Customer();
return _customerDao.GetCustomerById(customerId);
#endregion
#region IServiceCustomer Members
public IList&Domain.Entity.Customer& GetAll()
IList&Domain.Entity.Customer& cs = _customerDao.GetAll();
#endregion
#region IServiceCustomer Members
public void Add(Domain.Entity.Customer customer)
_customerDao.CreateCustomer(customer);
#endregion
#region IServiceCustomer Members
public string SayHello(SysUser sysUser)
_myValidator = (MyValidator)OperationContext.Current.Host.Credentials.UserNameAuthentication.CustomUserNamePasswordV
return string.Format("hello,{0},your password is {1}n{2}{3}", sysUser.UserName, sysUser.Password,
// _myValidator.ToString(),_myValidator.ToString() );
_myValidator.UserName ,_myValidator.Password );
#endregion
  Silverlight客户端前台代码
&!--&br/ /&&br/ /&Code highlighting produced by Actipro CodeHighlighter (freeware)&br/ /&/&br/ /&&br/ /&--&&UserControl xmlns:navigation="clr-namespace:System.Windows.Cassembly=System.Windows.Controls.Navigation"
xmlns="/winfx/2006/xaml/presentation"
xmlns:x="/winfx/2006/xaml"
xmlns:data="clr-namespace:System.Windows.Cassembly=System.Windows.Controls.Data" x:Class="Silverlight.sldbdemo"
Width="400"&
&ScrollViewer&
&StackPanel&
&Button x:Name="btnGetCustomer" Content="获取一个用户信息" Click="btnGetCustomer_Click"&&/Button&
&Grid x:Name="LayoutRoot" Background="White"&
&Grid.ColumnDefinitions&
&ColumnDefinition/&
&ColumnDefinition/&
&/Grid.ColumnDefinitions&
&Grid.RowDefinitions&
&RowDefinition Height="20"/&
&RowDefinition Height="20"/&
&RowDefinition Height="20"/&
&RowDefinition Height="20"/&
&RowDefinition Height="20"/&
&RowDefinition Height="20"/&
&/Grid.RowDefinitions&
&TextBlock x:Name="LblCustomerId" Grid.Column="0" Grid.Row="0" Text="Customer Id"/&
&TextBlock x:Name="TxtCustomerId" Grid.Column="1" Grid.Row="0" Text="{Binding CustomerId}"/&
&TextBlock x:Name="LblCustomerCode" Grid.Column="0" Grid.Row="1" Text="Customer Code"/&
&TextBlock x:Name="TxtCustomerCode" Grid.Column="1" Grid.Row="1" Text="{Binding CustomerCode}"/&
&TextBlock x:Name="LblCustomerName" Grid.Column="0" Grid.Row="2" Text="用户名称"/&
&TextBlock x:Name="TxtCustomerName" Grid.Column="1" Grid.Row="2" Text="{Binding CustomerName}"/&
&Button x:Name="btnGetAllCustomer" Content="获取全部用户信息" Click="btnGetAllCustomer_Click"&&/Button&
&Grid x:Name="customers" Background="Gray" Grid.ColumnSpan="2" Grid.Column="0" Grid.Row="3"&
&data:DataGrid x:Name="dataGrid" CanUserResizeColumns="true" CanUserSortColumns="True"
AutoGenerateColumns="False" ItemsSource="{Binding}"&
&data:DataGrid.Columns&
&data:DataGridTextColumn Header="Id" Binding="{Binding CustomerId}"&&/data:DataGridTextColumn&
&data:DataGridTextColumn Header="Code" Binding="{Binding CustomerCode}"&&/data:DataGridTextColumn&
&data:DataGridTextColumn Header="Name" Binding="{Binding CustomerName}"&&/data:DataGridTextColumn&
&/data:DataGrid.Columns&
&/data:DataGrid&
&StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4"&
&data:DataPager x:Name="tempPager" DisplayMode="FirstLastPreviousNextNumeric" HorizontalAlignment="Left" VerticalAlignment="Top"
Source="{Binding Path=ItemsSource,ElementName=dataGrid}"
PageSize="5"
&&/data:DataPager&
&/StackPanel&
&Grid x:Name="AddCustomer" Background="White" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="5" Height="97"&
&Grid.ColumnDefinitions &
&ColumnDefinition Width="0.5*"&&/ColumnDefinition&
&ColumnDefinition Width="0.5*"&&/ColumnDefinition&
&/Grid.ColumnDefinitions&
&Grid.RowDefinitions &
&RowDefinition Height="0.247*" &&/RowDefinition&
&RowDefinition Height="0.247*" &&/RowDefinition&
&RowDefinition Height="0.247*" &&/RowDefinition&
&RowDefinition Height="0.258*" &&/RowDefinition&
&/Grid.RowDefinitions&
&TextBlock Text="Customer Id" Grid.Column="0" Grid.Row="0"&&/TextBlock&
&TextBox x:Name="customerId" Grid.Column="1" Grid.Row="0"&&/TextBox&
&TextBlock Text="Custoemr Code" Grid.Column="0" Grid.Row="1"&&/TextBlock&
&TextBox x:Name="customerCode" Grid.Column="1" Grid.Row="1"&&/TextBox&
&TextBlock Text="Customer Name" Grid.Column="0" Grid.Row="2"&&/TextBlock&
&TextBox x:Name="customerName" Grid.Column="1" Grid.Row="2"&&/TextBox&
&Button x:Name="btnOk" Grid.Column="0" Grid.Row="3" Height="25" Content="添加用户Add Customer" Click="btnOk_Click"&&/Button&
&Button x:Name="btnLoadData" Click="btnLoadData_Click" Content="加载数据"&&/Button&
&ListBox x:Name="lstCustomers"&&/ListBox&
&/StackPanel&
&/ScrollViewer&
&/UserControl&
  Silverlight客户端后台代码
&!--&br/ /&&br/ /&Code highlighting produced by Actipro CodeHighlighter (freeware)&br/ /&/&br/ /&&br/ /&--&using S
using System.Collections.G
using System.L
using System.N
using System.W
using System.Windows.C
using System.Windows.D
using System.Windows.I
using System.Windows.M
using System.Windows.Media.A
using System.Windows.S
using Silverlight.ServiceC
using Domain.E
namespace Silverlight
用户评论(0)
开发技术学习小组列表
PHP开发框架
缓存Memcache
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
手机客户端
ThinkSAAS接收任何功能的Iphone(IOS)和Android手机的客户端定制开发服务
让ThinkSAAS更好,把建议拿来。
iphone扫码下载客户端SilverLight2 Beta2 学习研究04、数据绑定控件 - 心海巨澜 - 博客园
&&&&&本讲我们介绍silverLight的数据绑定控件:普通绑定控件、DataGrid控件、ListBox控件以及数据绑定的方式。
&&&&&数据绑定的方式分为三种:
&&&&&OneTime、一次性数据绑定,显示不会变更的数据,默认为这种方式,无需指定绑定模式。
&&&&&OneWay、单向数据绑定,显示数据时,如果后台数据变更,那么前台界面的显示也随之变更。指定绑定模式:Mode=OneWay。
&&&&&TwoWay、双向数据绑定,后台数据变更,前台界面显示的数据也随之变更;前台界面显示的数据用户可以改变,改变后,后台数据源的数据也随之变更。指定绑定模式:Mode=TwoWay。
&&&&&下面将通过介绍绑定控件介绍三种绑定模式。
1、普通绑定控件
&&&&&对于普通绑定控件,可以通过对其属性(Text或Content等)="{Binding 数据源的属性}",代码部分指定控件的DataContext=数据源对象,来实现数据绑定。本实例实现OneTime和OneWay方式,代码如下:&
&&&&&&& &StackPanel x:Name="sPanelBook" Margin="0,50,0,0" HorizontalAlignment="Center"&
&&&&&&&&&&& &StackPanel Orientation="Horizontal"&
&&&&&&&&&&&&&&& &TextBlock Text="书名:" FontSize="28" Foreground="Coral"/&
&&&&&&&&&&&&&&& &TextBlock x:Name="txtTitle" FontSize="28" Foreground="Coral" Text="{Binding Title, Mode=OneWay}" /&
&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&& &StackPanel Orientation="Horizontal"&
&&&&&&&&&&&&&&& &TextBlock Text="价格:" FontSize="28" Foreground="Coral"/&
&&&&&&&&&&&&&&& &ContentControl x:Name="txtPrice" FontSize="28" Foreground="Coral" Content="{Binding Price}" /&
&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&& &Button x:Name="btnUpdate" Content="更新书名" Click="btnUpdate_Click" FontSize="28" Foreground="DarkBlue" Width="400"/&
&&&&&&& &/StackPanel&
&&&&ponentM
&&& public partial class Page : UserControl
&&&&&&& public Page()
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& BindContext();
&&&&&&& private void BindContext()
&&&&&&&&&&& book = new Book { Title = "SilverLight 2.0 入门精典", Price = 28 };//C#3.0语法
&&&&&&&&&&& sPanelBook.DataContext =//此语句等同于下面的两句&&&&&&&&&&&
&&&&&&&&&&&
&&&&&&&&&&& //txtTitle.DataContext =
&&&&&&&&&&& //txtPrice.DataContext =
&&&&&&& private void btnUpdate_Click(object sender, RoutedEventArgs e)
&&&&&&&&&&& if (book.Title.Contains("入门精典"))
&&&&&&&&&&& {
&&&&&&&&&&&&&&& book.Title = "SilverLight 2.0 高级编程";//Title为OneWay绑定,所以前台会改变
&&&&&&&&&&&&&&& book.Price = 36;&&&&&&&&&&&&&&&&&&&&&&&&&&& //Price为OneTime绑定,所以前台不会改变
&&&&&&&&&&& }
&&&&&&&&&&& else
&&&&&&&&&&& {
&&&&&&&&&&&&&&& book.Title = "SilverLight 2.0 入门精典";//Title为OneWay绑定,所以前台会改变
&&&&&&&&&&&&&&& book.Price = 28;&&&&&&&&&&&&&&&&&&&&&&&&&&& //Price为OneTime绑定,所以前台不会改变
&&&&&&&&&&& }
&&& public class Book : INotifyPropertyChanged
&&&&&&& public event PropertyChangedEventHandler PropertyC
&&&&&&& private void NotifyPropertyChanged(String info)
&&&&&&&&&&& if (PropertyChanged != null)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& PropertyChanged(this, new PropertyChangedEventArgs(info));
&&&&&&&&&&& }
&&&&&&& private string title = string.E
&&&&&&& public string Title
&&&&&&&&&&& get { }
&&&&&&&&&&& set
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (value != title)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& title =
&&&&&&&&&&&&&&&&&&& NotifyPropertyChanged("Title");
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&& public decimal Price { }
运行效果如下:
2、DataGrid控件
&&&&&&DataGrid控件是一种以网格为主的数据绑定控件。它有五个重要属性:
&&&&&自动产生列(AutoGenerateColumns)、允许调整列大小(CanUserResizeColumns)、允许调整列排序(CanUserReorderColumns)、是否可以编辑(IsReadOnly)和数据源绑定对象(ItemsSource)。
&&&&&三个列对象:DataGridTextColumn、DataGridCheckBoxColumn和DataGridTemplateColumn。
&&&&&本实例实现Mode=TwoWay数据绑定模式,代码如下:&&&
&&&&&&& &my:DataGrid x:Name="dgTest" AutoGenerateColumns="False" Width="500" Margin="0,20,0,0"
&&&&&&&&&&&&&&&&&&& &HorizontalScrollBarVisibility="Auto" Height="450" VerticalScrollBarVisibility="Auto"&
&&&&&&&&&&& &my:DataGrid.Columns&
&&&&&&&&&&&&&&& &my:DataGridTextColumn Header="书名" DisplayMemberBinding="{Binding Title}"&&/my:DataGridTextColumn&
&&&&&&&&&&&&&&& &my:DataGridTextColumn Header="价格" DisplayMemberBinding="{Binding Price}"&&/my:DataGridTextColumn&
&&&&&&&&&&&&&&& &my:DataGridCheckBoxColumn Header="是否有货" DisplayMemberBinding="{Binding IsOOS}"&&/my:DataGridCheckBoxColumn&
&&&&&&&&&&&&&&& &my:DataGridTemplateColumn Header="出版日期"&
&&&&&&&&&&&&&&&&&&& &my:DataGridTemplateColumn.CellTemplate&
&&&&&&&&&&&&&&&&&&&&&&& &DataTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="{Binding PublishDate}"&&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&& &/DataTemplate&
&&&&&&&&&&&&&&&&&&& &/my:DataGridTemplateColumn.CellTemplate&
&&&&&&&&&&&&&&&&&&& &my:DataGridTemplateColumn.CellEditingTemplate&
&&&& &&&&&&&&&&&&&&&&&&&&DataTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &my1:DatePicker SelectedDate="{Binding PublishDate, Mode=TwoWay}"&&/my1:DatePicker&
&&&&&&&&&&&&&&&&&&&&&&& &/DataTemplate&
&&&&&&&&&&&&&&&&&&& &/my:DataGridTemplateColumn.CellEditingTemplate&
&&&&&&&&&&&&&&& &/my:DataGridTemplateColumn&
&&&&&&&&&&& &/my:DataGrid.Columns&
&&&&&&&&&&& &my:DataGrid.RowDetailsTemplate&
&&&&&&&&&&&&&&& &DataTemplate&
&&&&&&&&&&&&&&&&&&& &StackPanel&
&&&&&&&&&&&&&&&&&&&&&&& &StackPanel Orientation="Horizontal"&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="编号:" &&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="{Binding BookId}" &&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text=" 标题:" &&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="{Binding Title}" &&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text=" 价格:" &&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="{Binding Price}" &&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&&&&&&&&&&&&&& &Image Source="{Binding ImgPath}" Width="450"&&/Image&
&&&&&&&&&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&&&&&& &/DataTemplate&
&&&&&&&&&&& &/my:DataGrid.RowDetailsTemplate&
&&&&&&& &/my:DataGrid&&&&
&&& public partial class Page : UserControl
&&&&&&& public Page()
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& BindDataGrid();
&&&&&&& private void BindDataGrid()
&&&&&&&&&&& List&Book& list = new List&Book&();
&&&&&&&&&&& for (int i = 0; i & 10; ++i)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& list.Add(new Book
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& BookId = i,
&&&&&&&&&&&&&&&&&&& Title = "SilverLight 2.0 高级编程" + i.ToString(),
&&&&&&&&&&&&&&&&&&& Price = 28 + i,
&&&&&&&&&&&&&&&&&&& PublishDate = DateTime.Now.AddDays(i),
&&&&&&&&&&&&&&&&&&& IsOOS = 0 == (i % 2),
&&&&&&&&&&&&&&&&&&& ImgPath="logo.jpg"
&&&&&&&&&&&&&&& });
&&&&&&&&&&& }
&&&&&&&&&&& dgTest.ItemsSource =
&&& public class Book
&&&&&&& public int BookId { }
&&&&&&& public string Title{ }
&&&&&&& public decimal Price { }
&&&&&&& public DateTime PublishDate { }
&&&&&&& public bool IsOOS { }
&&&&&&& public string ImgPath { }
&运行效果如下:
3、ListBox控件
&&&&&&ListBox控件是一种以显示单项数据为主的数据绑定控件,它有三个重要属性:列表项(ListBoxItem)、项模板(ItemTemplate)和项绑定对象(ItemsSource)。代码如下:&
&&&&&&& &StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,20,0,0" &
&&&&&&&&&&& &StackPanel&
&&&&&&& &&&&&&&&&TextBlock Text="填充项" Margin="5,5,5,0" Foreground="Coral"/&
&&&&&&&&&&&&&&& &ListBox Height="300" Width="100" Margin="5,0,5,5"&
&&&&&&&&&&&&&&&&&&& &Rectangle Width="94" Height="30" Fill="Coral"/&
&&&&&&&&&&&&&&&&&&& &ListBoxItem Content="填充项A"/&
&&&&&&&&&&&&&&&&&&& &ListBoxItem Content="填充项B"/&
&&&&&&&&&&&&&&&&&&& &ListBoxItem Content="填充项C"/&
&&&&&&&&&&&&&&&&&&& &ListBoxItem Content="填充项D"/&
&&&&&&&&&&&&&&&&&&& &ListBoxItem Content="填充项E"/&
&&&&&&&&&&&&&&&&&&& &Ellipse Width="94" Height="30" Fill="Coral"&&/Ellipse&
&&&&&&&&&&&&&&& &/ListBox&
&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&& &StackPanel&
&&&&&&&&&&&&&&& &TextBlock Text="绑定到项" Margin="5,5,5,0" Foreground="Coral"/&
&&&&&&&&&&&&&&& &ListBox x:Name="lbItems" Height="300" Width="150" Margin="5,0,5,5"&
&&&&&&&&&&&&&&& &/ListBox&
&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&& &StackPanel&
&&&&&&&&&&&&&&& &TextBlock Text="绑定到项模板" Margin="5,5,5,0" Foreground="Coral"/&
&&&&&&&&&&&&&&& &ListBox x:Name="lbDataTemplate" Height="300" Width="400" Margin="5,0,5,5"&
&&&&&&&&&&&&&&&&&&& &ListBox.ItemTemplate&
&&&&&&&&&&&&&&&&&&&&&&& &DataTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &StackPanel&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &StackPanel Orientation="Horizontal"&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="{Binding Title}"&&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="&& "&&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &my:DatePicker SelectedDate="{Binding PublishDate}"&&/my:DatePicker&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &TextBlock Text="&& "&&/TextBlock&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &CheckBox IsChecked="{Binding IsOOS}"&&/CheckBox&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &Image Source="{Binding ImgPath}"/&
&&&&&&&&&&&&&&&&&&&&&&&&&&& &/StackPanel&
&&&&&&&&&&&&&&&&&&&&&&& &/DataTemplate&
&&&&&&&&&&&&&&&&&&& &/ListBox.ItemTemplate&
&&&&&&&&&&&&&&& &/ListBox&
&&&&&&&&&&& &/StackPanel&
&&&&&&& &/StackPanel&
&&& public partial class Page : UserControl
&&&&&&& public Page()
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& BindItems();
&&&&&&&&&&& BindDataTemplate();
&&&&&&& private void BindItems()
&&&&&&&&&&& List&string& list = new List&string&();
&&&&&&&&&&& for (int i = 0; i & 20; ++i)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& list.Add(i.ToString() + "SilverLight 2.0 高级编程");
&&&&&&&&&&& }
&&&&&&&&&&& lbItems.ItemsSource =
&&&&&&& private void BindDataTemplate()
&&&&&&&&&&& List&Book& list = new List&Book&();
&&&&&&&&&&& for (int i = 0; i & 10; ++i)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& list.Add(new Book
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& BookId = i,
&&&&&&&&&&&&&&&&&&& Title = "SilverLight 2.0 高级编程" + i.ToString(),
&&&&&&&&&&&&&&&&&&& Price = 28 + i,
&&&&&&&&&&&&&&&&&&& PublishDate = DateTime.Now.AddDays(i),
&&&&&&&&&&&&&&&&&&& IsOOS = 0 == (i % 2),
&&&&&&&&&&&&&&&&&&& ImgPath = "logo.jpg"
&&&&&&&&&&&&&&& });
&&&&&&&&&&& }
&&&&&&&&&&& lbDataTemplate.ItemsSource =
&&& public class Book
&&&&&&& public int BookId { }
&&&&&&& public string Title { }
&&&&&&& public decimal Price { }
&&&&&&& public DateTime PublishDate { }
&&&&&&& public bool IsOOS { }
&&&&&&& public string ImgPath { }
运行效果如下:
&&&&&综述:本部分主要讲了silverLight的数据绑定控件:普通绑定控件、DataGrid控件、ListBox控件,下一讲我们介绍silverLight的。C# DataGirdView 数据绑定后DataGridViewTextBoxColumn列转换成DataGridViewComb......谢谢,请指教。_百度知道
C# DataGirdView 数据绑定后DataGridViewTextBoxColumn列转换成DataGridViewComb......谢谢,请指教。
C# DataGirdView 数据绑定后DataGridViewTextBoxColumn列转换成DataGridViewComboBoxColumn需要如何操作?谢谢,请指教。
提问者采纳
这个是设置column的属性
/&#47.F;&#47.Fill.DataGridView控件;this.F
this貌似不可以,设定这个cell的值了; Column1
/看了上面的代码.Forms.DataGridViewColumn[] {
this.dataGridView1,然后在Designer,拖了个.Windows,怎么再换成ComboBox;/;这个是将column1.Windows.Windows.Column2}).DataGridViewComboBoxColumn().Column2 = new System.Windows.AutoSizeMode =
System.cs里面代码是这样的private System.Column1.DataGridViewTextBoxColumn Column1.Forms?补充;this.Column1:我试验了一下;Column1&quot.Windows.Column1 = new S/
this.Column1.FColumn1&quot,第一列是DataGridViewTextBoxColumn.DataGridViewComboBoxColumn Column2.Columns,第二列是DataGridViewComboBoxColumn,Column2放进dataGridViewthis.Name = &
&#47.DataGridViewAutoSizeColumnMode.Windows.Forms.HeaderText = &/private System.DataGridViewTextBoxColumn().Column1.AddRange(new System,
this,你都绑定数据了
提问者评价
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 datagridcolumn 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信