Created
July 20, 2018 07:01
-
-
Save polarstars/3874ba01400891b5a267975d055621ee to your computer and use it in GitHub Desktop.
#Telerik 中 RadDropDownList 显示图片列表 #C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
花不啰嗦,直接看代码,数据绑定到DataTable上,如果有多个控件绑定到一个DataTable上,你又不需要控件之间联动, | |
请添加类似“ddList.BindingContext = new BindingContext();”的代码。 | |
我看到国内很多人的帖子都是用的DataTable的Copy方法,在某些情况下能满足要求,如果DataTable数据是要变动的Copy | |
大法就GameOver了,还是多用内建的方法,很多功能微软都为我们考虑好了, 是我们自己学艺不精不甚了解罢了。 | |
========================================================================================================== | |
RadDropDownList ddList = new RadDropDownList(); | |
...............(其它属性设置省略) | |
ddList.BindingContext = new BindingContext(); | |
ddList.DataSource = FilesDataTable; | |
ddList.ListElement.AutoSizeItems = true; | |
ddList.DropDownSizingMode = Telerik.WinControls.UI.SizingMode.None; | |
ddList.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList; | |
ddList.ItemDataBound += (sender, e) => | |
{ | |
RadListDataItem item = e.NewItem; | |
item.Text = (item.DataBoundItem as DataRowView)["Name"].ToString(); | |
item.TextImageRelation = TextImageRelation.ImageBeforeText; | |
item.Image = LoadImage((item.DataBoundItem as DataRowView)["Path"].ToString()).GetThumbnailImage(100, 75, null, new IntPtr()); | |
}; | |
public Image LoadImage(string filePath) | |
{ | |
System.IO.FileStream fs = new System.IO.FileStream(filePath,System.IO.FileMode.Open, System.IO.FileAccess.Read); | |
Image image = System.Drawing.Image.FromStream(fs); | |
fs.Close(); | |
return image; | |
} | |
其中 FilesDataTable 是一个DataTable ,其中包含2列,列名分别为 “Name”和“Path”,分别存储图片的文件名和全路径,GetThumbnailImage是C#内建的取缩略图的方法。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment