ListView.cs 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. //
  2. // System.Web.UI.WebControls.ListView
  3. //
  4. // Authors:
  5. // Marek Habersack ([email protected])
  6. //
  7. // (C) 2007 Novell, Inc
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_3_5
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using System.Collections.Specialized;
  34. using System.ComponentModel;
  35. using System.Drawing;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.HtmlControls;
  39. namespace System.Web.UI.WebControls
  40. {
  41. [DefaultEventAttribute ("SelectedIndexChanged")]
  42. [ControlValuePropertyAttribute ("SelectedValue")]
  43. [DesignerAttribute ("System.Web.UI.Design.WebControls.ListViewDesigner, System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  44. [SupportsEventValidationAttribute ()]
  45. [ToolboxBitmapAttribute (typeof (ListView), "ListView.ico")]
  46. [DefaultPropertyAttribute ("SelectedValue")]
  47. public class ListView : DataBoundControl, INamingContainer, IPageableItemContainer
  48. {
  49. ITemplate _emptyDataTemplate;
  50. ITemplate _emptyItemTemplate;
  51. ITemplate _insertItemTemplate;
  52. ITemplate _groupSeparatorTemplate;
  53. ITemplate _groupTemplate;
  54. ITemplate _itemSeparatorTemplate;
  55. ITemplate _itemTemplate;
  56. ITemplate _selectedItemTemplate;
  57. ITemplate _alternatingItemTemplate;
  58. ITemplate _editItemTemplate;
  59. ITemplate _layoutTemplate;
  60. int _startRowIndex;
  61. int _maximumRows;
  62. int _selectedIndex;
  63. int _editIndex;
  64. int _groupItemCount;
  65. string [] _dataKeyNames;
  66. DataKeyArray _dataKeys;
  67. ArrayList _dataKeyArray;
  68. SortDirection _sortDirection = SortDirection.Ascending;
  69. string _sortExpression = String.Empty;
  70. Control _layoutTemplatePlaceholder;
  71. IOrderedDictionary _lastInsertValues;
  72. public ListView ()
  73. {
  74. InsertItemPosition = InsertItemPosition.None;
  75. }
  76. protected virtual void AddControlToContainer (Control control, Control container, int addLocation)
  77. {
  78. if (control == null || container == null)
  79. return;
  80. Control ctl;
  81. if (container is HtmlTable) {
  82. ctl = new ListViewTableRow ();
  83. ctl.Controls.Add (control);
  84. } else
  85. ctl = control;
  86. container.Controls.AddAt (addLocation, ctl);
  87. }
  88. protected internal override void CreateChildControls ()
  89. {
  90. if (RequiresDataBinding)
  91. EnsureDataBound ();
  92. base.CreateChildControls ();
  93. }
  94. protected virtual int CreateChildControls (IEnumerable dataSource, bool dataBinding)
  95. {
  96. IList <ListViewDataItem> retList = null;
  97. EnsureLayoutTemplate ();
  98. RemoveItems ();
  99. bool haveDataToDisplay = _maximumRows > 0 && _startRowIndex > 0;
  100. var pagedDataSource = new ListViewPagedDataSource ();
  101. if (dataBinding) {
  102. DataSourceView view = GetData ();
  103. if (view == null)
  104. throw new InvalidOperationException ("dataSource returned a null reference for DataSourceView.");
  105. if (!(dataSource is ICollection))
  106. throw new InvalidOperationException ("dataSource does not implement the ICollection interface.");
  107. int totalRowCount = 0;
  108. if (haveDataToDisplay) {
  109. if (view.CanRetrieveTotalRowCount)
  110. totalRowCount = SelectArguments.TotalRowCount;
  111. else
  112. totalRowCount = ((ICollection) dataSource).Count + _startRowIndex;
  113. }
  114. pagedDataSource.StartRowIndex = _startRowIndex;
  115. pagedDataSource.DataSource = dataSource;
  116. pagedDataSource.TotalRowCount = totalRowCount;
  117. } else {
  118. if (!(dataSource is ICollection))
  119. throw new InvalidOperationException ("dataSource does not implement the ICollection interface and dataBinding is false.");
  120. }
  121. if (GroupItemCount <= 0) {
  122. retList = CreateItemsWithoutGroups (pagedDataSource, dataBinding, InsertItemPosition, DataKeyArray);
  123. Console.WriteLine ("Data key names:");
  124. foreach (string s in DataKeyNames)
  125. Console.WriteLine ("\t{0}", s);
  126. Console.WriteLine ("Keys:");
  127. foreach (object o in DataKeyArray)
  128. Console.WriteLine ("\t{0}", o);
  129. }
  130. if (retList == null)
  131. return 0;
  132. return retList.Count;
  133. }
  134. protected override Style CreateControlStyle ()
  135. {
  136. throw StylingNotSupported ();
  137. }
  138. protected virtual ListViewDataItem CreateDataItem (int dataItemIndex, int displayIndex)
  139. {
  140. return new ListViewDataItem (dataItemIndex, displayIndex);
  141. }
  142. protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
  143. {
  144. DataSourceSelectArguments arg = DataSourceSelectArguments.Empty;
  145. DataSourceView view = GetData();
  146. if (view.CanPage) {
  147. arg.StartRowIndex = _startRowIndex;
  148. if (view.CanRetrieveTotalRowCount) {
  149. arg.RetrieveTotalRowCount = true;
  150. arg.MaximumRows = _maximumRows;
  151. } else
  152. arg.MaximumRows = -1;
  153. }
  154. if (IsBoundUsingDataSourceID && !String.IsNullOrEmpty (_sortExpression)) {
  155. if (_sortDirection == SortDirection.Ascending)
  156. arg.SortExpression = _sortExpression;
  157. else
  158. arg.SortExpression = _sortExpression + " DESC";
  159. }
  160. return arg;
  161. }
  162. protected virtual void CreateEmptyDataItem ()
  163. {
  164. if (_emptyDataTemplate != null) {
  165. ListViewItem item = CreateItem (ListViewItemType.EmptyItem);
  166. InstantiateEmptyDataTemplate (item);
  167. OnItemCreated (new ListViewItemEventArgs (item));
  168. AddControlToContainer (item, this, 0);
  169. }
  170. }
  171. protected virtual ListViewItem CreateEmptyItem ()
  172. {
  173. if (_emptyDataTemplate != null) {
  174. ListViewItem item = CreateItem (ListViewItemType.EmptyItem);
  175. InstantiateEmptyItemTemplate (item);
  176. OnItemCreated (new ListViewItemEventArgs (item));
  177. return item;
  178. }
  179. return null;
  180. }
  181. protected virtual ListViewItem CreateInsertItem ()
  182. {
  183. ListViewItem ret = CreateItem (ListViewItemType.InsertItem);
  184. InsertItem = ret;
  185. return ret;
  186. }
  187. protected virtual ListViewItem CreateItem (ListViewItemType itemType)
  188. {
  189. return new ListViewItem (itemType);
  190. }
  191. protected virtual IList <ListViewDataItem> CreateItemsInGroups (ListViewPagedDataSource dataSource, bool dataBinding, InsertItemPosition insertPosition,
  192. ArrayList keyArray)
  193. {
  194. if (_groupTemplate == null)
  195. return null;
  196. throw new NotImplementedException ();
  197. }
  198. protected virtual IList <ListViewDataItem> CreateItemsWithoutGroups (ListViewPagedDataSource dataSource, bool dataBinding,
  199. InsertItemPosition insertPosition, ArrayList keyArray)
  200. {
  201. Control contentPlaceholder = FindPlaceholder (ItemPlaceholderID, _layoutTemplatePlaceholder);
  202. if (contentPlaceholder == null)
  203. return new List <ListViewDataItem> ();
  204. Control parent = contentPlaceholder.Parent;
  205. int ipos = 0;
  206. if (parent != null) {
  207. ipos = parent.Controls.IndexOf (contentPlaceholder);
  208. parent.Controls.Remove (contentPlaceholder);
  209. contentPlaceholder = parent;
  210. AddControlToContainer (contentPlaceholder, _layoutTemplatePlaceholder, 0);
  211. }
  212. List <ListViewDataItem> ret = new List <ListViewDataItem> ();
  213. ListViewItem lvi;
  214. ListViewItem container;
  215. bool needSeparator = false;
  216. if (insertPosition == InsertItemPosition.FirstItem) {
  217. lvi = CreateInsertItem ();
  218. InstantiateInsertItemTemplate (lvi);
  219. AddControlToContainer (lvi, contentPlaceholder, ipos++);
  220. needSeparator = true;
  221. }
  222. bool haveSeparatorTemplate = _itemSeparatorTemplate != null;
  223. int displayIndex = 0;
  224. ListViewDataItem lvdi;
  225. int startIndex = dataSource.StartRowIndex;
  226. foreach (object item in dataSource) {
  227. if (needSeparator && haveSeparatorTemplate) {
  228. container = new ListViewItem ();
  229. InstantiateItemSeparatorTemplate (container);
  230. AddControlToContainer (container, contentPlaceholder, ipos++);
  231. }
  232. lvdi = CreateDataItem (startIndex + displayIndex, displayIndex);
  233. InstantiateItemTemplate (lvdi, displayIndex);
  234. if (dataBinding) {
  235. lvdi.DataItem = item;
  236. OrderedDictionary dict = new OrderedDictionary ();
  237. string[] dataKeyNames = DataKeyNames;
  238. foreach (string s in dataKeyNames)
  239. dict.Add (s, DataBinder.GetPropertyValue (item, s));
  240. DataKey dk = new DataKey (dict, dataKeyNames);
  241. if (keyArray.Count == displayIndex)
  242. keyArray.Add (dk);
  243. else
  244. keyArray [displayIndex] = dk;
  245. }
  246. OnItemCreated (new ListViewItemEventArgs (lvdi));
  247. AddControlToContainer (lvdi, contentPlaceholder, ipos++);
  248. if (!needSeparator)
  249. needSeparator = true;
  250. if (dataBinding) {
  251. lvdi.DataBind ();
  252. OnItemDataBound (new ListViewItemEventArgs (lvdi));
  253. }
  254. displayIndex++;
  255. ret.Add (lvdi);
  256. }
  257. if (insertPosition == InsertItemPosition.LastItem) {
  258. if (needSeparator && haveSeparatorTemplate) {
  259. container = new ListViewItem ();
  260. InstantiateItemSeparatorTemplate (container);
  261. AddControlToContainer (container, contentPlaceholder, ipos++);
  262. }
  263. lvi = CreateInsertItem ();
  264. InstantiateInsertItemTemplate (lvi);
  265. AddControlToContainer (lvi, contentPlaceholder, ipos++);
  266. }
  267. return ret;
  268. }
  269. protected virtual void CreateLayoutTemplate ()
  270. {
  271. if (_layoutTemplate != null) {
  272. _layoutTemplatePlaceholder = new Control ();
  273. _layoutTemplate.InstantiateIn (_layoutTemplatePlaceholder);
  274. AddControlToContainer (_layoutTemplatePlaceholder, this, 0);
  275. }
  276. OnLayoutCreated (EventArgs.Empty);
  277. }
  278. public virtual void DeleteItem (int itemIndex)
  279. {
  280. }
  281. protected virtual void EnsureLayoutTemplate ()
  282. {
  283. Controls.Clear ();
  284. CreateLayoutTemplate ();
  285. }
  286. public virtual void ExtractItemValues (IOrderedDictionary itemValues, ListViewItem item, bool includePrimaryKey)
  287. {
  288. if (itemValues == null)
  289. throw new ArgumentNullException ("itemValues");
  290. if (!(item is ListViewDataItem))
  291. throw new InvalidOperationException ("item is not a ListViewDataItem object.");
  292. }
  293. protected virtual Control FindPlaceholder (string containerID, Control container)
  294. {
  295. if (container == null || String.IsNullOrEmpty (containerID))
  296. return null;
  297. return container.FindControl (containerID);
  298. }
  299. public virtual void InsertNewItem (bool causesValidation)
  300. {
  301. ListViewItem insertItem = InsertItem;
  302. if (insertItem == null)
  303. throw new InvalidOperationException ("The ListView control does not have an insert item.");
  304. DataSourceView dsv = null;
  305. ListViewInsertEventArgs eventArgs = null;
  306. if (IsBoundUsingDataSourceID) {
  307. dsv = GetData ();
  308. if (dsv == null)
  309. throw new InvalidOperationException ("Missing data.");
  310. eventArgs = new ListViewInsertEventArgs (insertItem);
  311. ExtractItemValues (eventArgs.Values, insertItem, true);
  312. } else
  313. eventArgs = new ListViewInsertEventArgs (insertItem);
  314. OnItemInserting (eventArgs);
  315. if (!eventArgs.Cancel && IsBoundUsingDataSourceID) {
  316. _lastInsertValues = eventArgs.Values;
  317. dsv.Insert (_lastInsertValues, new DataSourceViewOperationCallback (InsertNewItemCallback));
  318. }
  319. }
  320. bool InsertNewItemCallback (int recordsAffected, Exception ex)
  321. {
  322. var eventArgs = new ListViewInsertedEventArgs (_lastInsertValues, recordsAffected, ex);
  323. OnItemInserted (eventArgs);
  324. _lastInsertValues = null;
  325. if (ex != null && !eventArgs.ExceptionHandled)
  326. return false;
  327. // This will effectively reset the insert values
  328. if (!eventArgs.KeepInInsertMode)
  329. RequiresDataBinding = true;
  330. return true;
  331. }
  332. protected virtual void InstantiateEmptyDataTemplate (Control container)
  333. {
  334. if (_emptyDataTemplate != null)
  335. _emptyDataTemplate.InstantiateIn (container);
  336. }
  337. protected virtual void InstantiateEmptyItemTemplate (Control container)
  338. {
  339. if (_emptyItemTemplate != null)
  340. _emptyItemTemplate.InstantiateIn (container);
  341. }
  342. protected virtual void InstantiateGroupSeparatorTemplate (Control container)
  343. {
  344. if (_groupSeparatorTemplate != null)
  345. _groupSeparatorTemplate.InstantiateIn (container);
  346. }
  347. protected virtual void InstantiateGroupTemplate (Control container)
  348. {
  349. if (_groupTemplate != null)
  350. _groupTemplate.InstantiateIn (container);
  351. }
  352. protected virtual void InstantiateInsertItemTemplate (Control container)
  353. {
  354. if (_insertItemTemplate != null)
  355. _insertItemTemplate.InstantiateIn (container);
  356. }
  357. protected virtual void InstantiateItemSeparatorTemplate (Control container)
  358. {
  359. if (_itemSeparatorTemplate != null)
  360. _itemSeparatorTemplate.InstantiateIn (container);
  361. }
  362. protected virtual void InstantiateItemTemplate (Control container, int displayIndex)
  363. {
  364. if (_itemTemplate == null)
  365. throw new InvalidOperationException ("ItemTemplate is missing");
  366. ITemplate template = _itemTemplate;
  367. if ((displayIndex % 2 != 0) && _alternatingItemTemplate != null)
  368. template = _alternatingItemTemplate;
  369. if ((displayIndex == _selectedIndex) && _selectedItemTemplate != null)
  370. template = _selectedItemTemplate;
  371. if ((displayIndex == _editIndex) && _editItemTemplate != null)
  372. template = _editItemTemplate;
  373. template.InstantiateIn (container);
  374. }
  375. protected override void LoadControlState (object savedState)
  376. {
  377. }
  378. protected override void LoadViewState (object savedState)
  379. {
  380. }
  381. protected override bool OnBubbleEvent (object source, EventArgs e)
  382. {
  383. throw new NotImplementedException ();
  384. }
  385. protected override void OnInit (EventArgs e)
  386. {
  387. }
  388. protected virtual void OnItemCanceling (ListViewCancelEventArgs e)
  389. {
  390. }
  391. protected virtual void OnItemCommand (ListViewCommandEventArgs e)
  392. {
  393. }
  394. protected virtual void OnItemCreated (ListViewItemEventArgs e)
  395. {
  396. }
  397. protected virtual void OnItemDataBound (ListViewItemEventArgs e)
  398. {
  399. }
  400. protected virtual void OnItemDeleted (ListViewDeletedEventArgs e)
  401. {
  402. }
  403. protected virtual void OnItemDeleting (ListViewDeleteEventArgs e)
  404. {
  405. }
  406. protected virtual void OnItemEditing (ListViewEditEventArgs e)
  407. {
  408. }
  409. protected virtual void OnItemInserted (ListViewInsertedEventArgs e)
  410. {
  411. }
  412. protected virtual void OnItemInserting (ListViewInsertEventArgs e)
  413. {
  414. }
  415. protected virtual void OnItemUpdated (ListViewUpdatedEventArgs e)
  416. {
  417. }
  418. protected virtual void OnItemUpdating (ListViewUpdateEventArgs e)
  419. {
  420. }
  421. protected virtual void OnLayoutCreated (EventArgs e)
  422. {
  423. }
  424. protected virtual void OnPagePropertiesChanged (EventArgs e)
  425. {
  426. }
  427. protected virtual void OnPagePropertiesChanging (PagePropertiesChangingEventArgs e)
  428. {
  429. }
  430. protected virtual void OnSelectedIndexChanged (EventArgs e)
  431. {
  432. }
  433. protected virtual void OnSelectedIndexChanging (ListViewSelectEventArgs e)
  434. {
  435. }
  436. protected virtual void OnSorted (EventArgs e)
  437. {
  438. }
  439. protected virtual void OnSorting (ListViewSortEventArgs e)
  440. {
  441. }
  442. protected virtual void OnTotalRowCountAvailable (PageEventArgs e)
  443. {
  444. }
  445. protected override void PerformDataBinding (IEnumerable data)
  446. {
  447. base.PerformDataBinding (data);
  448. TrackViewState ();
  449. int childCount = CreateChildControls (data, true);
  450. ChildControlsCreated = true;
  451. }
  452. protected override void PerformSelect ()
  453. {
  454. EnsureLayoutTemplate ();
  455. base.PerformSelect ();
  456. }
  457. protected virtual void RemoveItems ()
  458. {
  459. }
  460. protected override void Render (HtmlTextWriter writer)
  461. {
  462. base.Render (writer);
  463. }
  464. protected override object SaveControlState ()
  465. {
  466. throw new NotImplementedException ();
  467. }
  468. protected override object SaveViewState ()
  469. {
  470. object[] states = new object [2];
  471. states [0] = base.SaveViewState ();
  472. states [1] = null;
  473. return states;
  474. }
  475. protected virtual void SetPageProperties (int startRowIndex, int maximumRows, bool databind)
  476. {
  477. }
  478. public virtual void Sort (string sortExpression, SortDirection sortDirection)
  479. {
  480. }
  481. void IPageableItemContainer.SetPageProperties (int startRowIndex, int maximumRows, bool databind)
  482. {
  483. throw new NotImplementedException ();
  484. }
  485. public virtual void UpdateItem (int itemIndex, bool causesValidation)
  486. {
  487. }
  488. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  489. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  490. [BrowsableAttribute (false)]
  491. public override string AccessKey {
  492. get { return base.AccessKey; }
  493. set { throw StylingNotSupported (); }
  494. }
  495. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  496. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  497. [DefaultValueAttribute (null)]
  498. [BrowsableAttribute (false)]
  499. public virtual ITemplate AlternatingItemTemplate {
  500. get { return _alternatingItemTemplate; }
  501. set { _alternatingItemTemplate = value; }
  502. }
  503. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  504. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  505. [BrowsableAttribute (false)]
  506. public override Color BackColor {
  507. get { return base.BackColor; }
  508. set { throw StylingNotSupported (); }
  509. }
  510. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  511. [BrowsableAttribute (false)]
  512. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  513. public override Color BorderColor {
  514. get { return base.BorderColor; }
  515. set { throw StylingNotSupported (); }
  516. }
  517. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  518. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  519. [BrowsableAttribute (false)]
  520. public override BorderStyle BorderStyle {
  521. get { return base.BorderStyle; }
  522. set { throw StylingNotSupported (); }
  523. }
  524. [BrowsableAttribute (false)]
  525. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  526. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  527. public override Unit BorderWidth {
  528. get { return base.BorderWidth; }
  529. set { throw StylingNotSupported (); }
  530. }
  531. public override ControlCollection Controls {
  532. get {
  533. EnsureChildControls ();
  534. return base.Controls;
  535. }
  536. }
  537. [CategoryAttribute ("Behavior")]
  538. [DefaultValueAttribute (true)]
  539. public virtual bool ConvertEmptyStringToNull {
  540. get {
  541. object o = ViewState ["ConvertEmptyStringToNull"];
  542. if (o != null)
  543. return (bool) o;
  544. return true;
  545. }
  546. set { ViewState ["ConvertEmptyStringToNull"] = value; }
  547. }
  548. public override string CssClass {
  549. get { return base.CssClass; }
  550. set { throw StylingNotSupported (); }
  551. }
  552. [DefaultValueAttribute (null)]
  553. [TypeConverterAttribute (typeof (StringArrayConverter))]
  554. [CategoryAttribute ("Data")]
  555. public virtual string [] DataKeyNames {
  556. get {
  557. if (_dataKeyNames != null)
  558. return _dataKeyNames;
  559. return new string [0];
  560. }
  561. set {
  562. if (value == null)
  563. _dataKeyNames = null;
  564. else
  565. _dataKeyNames = (string []) value.Clone ();
  566. // They will eventually be recreated when data binding
  567. _dataKeyArray = null;
  568. _dataKeys = null;
  569. if (Initialized)
  570. RequiresDataBinding = true;
  571. }
  572. }
  573. [BrowsableAttribute (false)]
  574. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  575. public virtual DataKeyArray DataKeys {
  576. get {
  577. if (_dataKeys == null) {
  578. _dataKeys = new DataKeyArray (DataKeyArray);
  579. if (IsTrackingViewState)
  580. ((IStateManager) _dataKeys).TrackViewState ();
  581. }
  582. return _dataKeys;
  583. }
  584. }
  585. ArrayList DataKeyArray {
  586. get {
  587. if (_dataKeyArray == null)
  588. _dataKeyArray = new ArrayList ();
  589. return _dataKeyArray;
  590. }
  591. }
  592. [DefaultValueAttribute (-1)]
  593. [CategoryAttribute ("Misc")]
  594. public virtual int EditIndex {
  595. get { return _editIndex; }
  596. set {
  597. if (value < -1)
  598. throw new ArgumentOutOfRangeException ("value");
  599. if (value != _editIndex) {
  600. _editIndex = value;
  601. if (Initialized)
  602. RequiresDataBinding = true;
  603. }
  604. }
  605. }
  606. [BrowsableAttribute (false)]
  607. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  608. public virtual ListViewItem EditItem {
  609. get { throw new NotImplementedException (); }
  610. }
  611. [DefaultValueAttribute (null)]
  612. [BrowsableAttribute (false)]
  613. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  614. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  615. public virtual ITemplate EditItemTemplate {
  616. get { return _editItemTemplate; }
  617. set { _editItemTemplate = value; }
  618. }
  619. [DefaultValueAttribute (null)]
  620. [TemplateContainerAttribute (typeof (ListView))]
  621. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  622. [BrowsableAttribute (false)]
  623. public virtual ITemplate EmptyDataTemplate {
  624. get { return _emptyDataTemplate; }
  625. set { _emptyDataTemplate = value; }
  626. }
  627. [TemplateContainerAttribute (typeof (ListViewItem))]
  628. [DefaultValueAttribute (null)]
  629. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  630. [BrowsableAttribute (false)]
  631. public virtual ITemplate EmptyItemTemplate {
  632. get { return _emptyItemTemplate; }
  633. set { _emptyItemTemplate = value; }
  634. }
  635. [BrowsableAttribute (false)]
  636. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  637. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  638. public override FontInfo Font {
  639. get { throw StylingNotSupported (); }
  640. }
  641. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  642. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  643. [BrowsableAttribute (false)]
  644. public override Color ForeColor {
  645. get { return base.ForeColor; }
  646. set { throw StylingNotSupported (); }
  647. }
  648. [CategoryAttribute ("Misc")]
  649. [DefaultValueAttribute (1)]
  650. public virtual int GroupItemCount {
  651. get { return _groupItemCount; }
  652. set {
  653. if (value < 1)
  654. throw new ArgumentOutOfRangeException ("value");
  655. if (value != _groupItemCount) {
  656. _groupItemCount = value;
  657. if (Initialized)
  658. RequiresDataBinding = true;
  659. }
  660. }
  661. }
  662. [CategoryAttribute ("Behavior")]
  663. [DefaultValueAttribute ("groupPlaceholder")]
  664. public virtual string GroupPlaceholderID {
  665. get {
  666. string s = ViewState ["GroupPlaceholderID"] as string;
  667. if (s != null)
  668. return s;
  669. return "groupPlaceHolder";
  670. }
  671. set {
  672. if (String.IsNullOrEmpty (value))
  673. throw new ArgumentOutOfRangeException ("value");
  674. ViewState ["GroupPlaceholderID"] = value;
  675. }
  676. }
  677. [BrowsableAttribute (false)]
  678. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  679. [DefaultValueAttribute (null)]
  680. [TemplateContainerAttribute (typeof (ListViewItem))]
  681. public virtual ITemplate GroupSeparatorTemplate {
  682. get { return _groupSeparatorTemplate; }
  683. set { _groupSeparatorTemplate = value; }
  684. }
  685. [TemplateContainerAttribute (typeof (ListViewItem))]
  686. [DefaultValueAttribute (null)]
  687. [BrowsableAttribute (false)]
  688. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  689. public virtual ITemplate GroupTemplate {
  690. get { return _groupTemplate; }
  691. set { _groupTemplate = value; }
  692. }
  693. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  694. [BrowsableAttribute (false)]
  695. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  696. public override Unit Height {
  697. get { return base.Height; }
  698. set { throw StylingNotSupported (); }
  699. }
  700. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  701. [BrowsableAttribute (false)]
  702. public virtual ListViewItem InsertItem {
  703. get;
  704. private set;
  705. }
  706. [CategoryAttribute ("Misc")]
  707. [DefaultValueAttribute (InsertItemPosition.None)]
  708. public virtual InsertItemPosition InsertItemPosition {
  709. get;
  710. set;
  711. }
  712. [TemplateContainerAttribute (typeof (ListViewItem), BindingDirection.TwoWay)]
  713. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  714. [DefaultValueAttribute (null)]
  715. [BrowsableAttribute (false)]
  716. public virtual ITemplate InsertItemTemplate {
  717. get { return _insertItemTemplate; }
  718. set { _insertItemTemplate = value; }
  719. }
  720. [DefaultValueAttribute ("itemPlaceholder")]
  721. [CategoryAttribute ("Behavior")]
  722. public virtual string ItemPlaceholderID {
  723. get {
  724. string s = ViewState ["ItemPlaceHolderID"] as string;
  725. if (s != null)
  726. return s;
  727. return "itemPlaceholder";
  728. }
  729. set {
  730. if (String.IsNullOrEmpty (value))
  731. throw new ArgumentOutOfRangeException ("value");
  732. ViewState ["ItemPlaceHolderID"] = value;
  733. }
  734. }
  735. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  736. [BrowsableAttribute (false)]
  737. public virtual IList <ListViewDataItem> Items {
  738. get { throw new NotImplementedException (); }
  739. }
  740. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  741. [BrowsableAttribute (false)]
  742. [TemplateContainerAttribute (typeof (ListViewItem))]
  743. [DefaultValueAttribute (null)]
  744. public virtual ITemplate ItemSeparatorTemplate {
  745. get { return _itemSeparatorTemplate; }
  746. set { _itemSeparatorTemplate = value; }
  747. }
  748. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  749. [DefaultValueAttribute (null)]
  750. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  751. [BrowsableAttribute (false)]
  752. public virtual ITemplate ItemTemplate {
  753. get { return _itemTemplate; }
  754. set { _itemTemplate = value; }
  755. }
  756. [TemplateContainerAttribute (typeof (ListView))]
  757. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  758. [DefaultValueAttribute (null)]
  759. [BrowsableAttribute (false)]
  760. public virtual ITemplate LayoutTemplate {
  761. get { return _layoutTemplate; }
  762. set { _layoutTemplate = value; }
  763. }
  764. protected virtual int MaximumRows {
  765. get { return _maximumRows; }
  766. }
  767. [BrowsableAttribute (false)]
  768. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  769. public virtual DataKey SelectedDataKey {
  770. get {
  771. if (_dataKeyNames == null || _dataKeyNames.Length == 0)
  772. throw new InvalidOperationException ("No data keys are specified in the DataKeyNames property.");
  773. DataKeyArray dataKeys = DataKeys;
  774. int selIndex = SelectedIndex;
  775. if (selIndex > -1 || selIndex < dataKeys.Count)
  776. return dataKeys [selIndex];
  777. return null;
  778. }
  779. }
  780. [CategoryAttribute ("Misc")]
  781. [DefaultValueAttribute (-1)]
  782. public virtual int SelectedIndex {
  783. get { return _selectedIndex; }
  784. set {
  785. if (value < -1)
  786. throw new ArgumentOutOfRangeException ("value");
  787. if (value != _selectedIndex) {
  788. _selectedIndex = value;
  789. if (Initialized)
  790. RequiresDataBinding = true;
  791. }
  792. }
  793. }
  794. [BrowsableAttribute (false)]
  795. [DefaultValueAttribute (null)]
  796. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  797. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  798. public virtual ITemplate SelectedItemTemplate {
  799. get { return _selectedItemTemplate; }
  800. set { _selectedItemTemplate = value; }
  801. }
  802. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  803. [BrowsableAttribute (false)]
  804. public object SelectedValue {
  805. get {
  806. DataKey dk = SelectedDataKey;
  807. if (dk != null)
  808. return dk.Value;
  809. return null;
  810. }
  811. }
  812. [DefaultValueAttribute (SortDirection.Ascending)]
  813. [BrowsableAttribute (false)]
  814. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  815. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  816. public virtual SortDirection SortDirection {
  817. get { return _sortDirection; }
  818. }
  819. [BrowsableAttribute (false)]
  820. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  821. public virtual string SortExpression {
  822. get { return _sortExpression; }
  823. }
  824. protected virtual int StartRowIndex {
  825. get { return _startRowIndex; }
  826. }
  827. int IPageableItemContainer.MaximumRows {
  828. get { return _maximumRows; }
  829. }
  830. int IPageableItemContainer.StartRowIndex {
  831. get { return _startRowIndex; }
  832. }
  833. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  834. [BrowsableAttribute (false)]
  835. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  836. public override short TabIndex {
  837. get { return 0; }
  838. set { throw new NotSupportedException ("ListView does not allow setting this property."); }
  839. }
  840. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  841. [BrowsableAttribute (false)]
  842. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  843. public override string ToolTip {
  844. get { return base.ToolTip; }
  845. set { throw StylingNotSupported (); }
  846. }
  847. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  848. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  849. [BrowsableAttribute (false)]
  850. public override Unit Width {
  851. get { return base.Width; }
  852. set { throw StylingNotSupported (); }
  853. }
  854. [CategoryAttribute ("Action")]
  855. public event EventHandler <ListViewCancelEventArgs> ItemCanceling;
  856. [CategoryAttribute ("Action")]
  857. public event EventHandler <ListViewCommandEventArgs> ItemCommand;
  858. [CategoryAttribute ("Behavior")]
  859. public event EventHandler <ListViewItemEventArgs> ItemCreated;
  860. [CategoryAttribute ("Data")]
  861. public event EventHandler <ListViewItemEventArgs> ItemDataBound;
  862. [CategoryAttribute ("Action")]
  863. public event EventHandler <ListViewDeletedEventArgs> ItemDeleted;
  864. [CategoryAttribute ("Action")]
  865. public event EventHandler <ListViewDeleteEventArgs> ItemDeleting;
  866. [CategoryAttribute ("Action")]
  867. public event EventHandler <ListViewEditEventArgs> ItemEditing;
  868. [CategoryAttribute ("Action")]
  869. public event EventHandler <ListViewInsertedEventArgs> ItemInserted;
  870. [CategoryAttribute ("Action")]
  871. public event EventHandler <ListViewInsertEventArgs> ItemInserting;
  872. [CategoryAttribute ("Action")]
  873. public event EventHandler <ListViewUpdatedEventArgs> ItemUpdated;
  874. [CategoryAttribute ("Action")]
  875. public event EventHandler <ListViewUpdateEventArgs> ItemUpdating;
  876. [CategoryAttribute ("Behavior")]
  877. public event EventHandler LayoutCreated;
  878. [CategoryAttribute ("Behavior")]
  879. public event EventHandler PagePropertiesChanged;
  880. [CategoryAttribute ("Behavior")]
  881. public event EventHandler <PagePropertiesChangingEventArgs> PagePropertiesChanging;
  882. [CategoryAttribute ("Action")]
  883. public event EventHandler SelectedIndexChanged;
  884. [CategoryAttribute ("Action")]
  885. public event EventHandler <ListViewSelectEventArgs> SelectedIndexChanging;
  886. [CategoryAttribute ("Action")]
  887. public event EventHandler Sorted;
  888. [CategoryAttribute ("Action")]
  889. public event EventHandler <ListViewSortEventArgs> Sorting;
  890. event EventHandler <PageEventArgs> IPageableItemContainer.TotalRowCountAvailable {
  891. add {
  892. }
  893. remove {
  894. }
  895. }
  896. NotSupportedException StylingNotSupported ()
  897. {
  898. return new NotSupportedException ("Style properties are not supported on ListView. Apply styling or CSS classes to the elements in the ListView's templates.");
  899. }
  900. }
  901. }
  902. #endif