Custom DropDownList
I am trying to have a DropDownList that allows a user to select an index (a row) not by the user just clicking on the row, but rather by the user doing a mouse-down on the row and then dragging the row a little to the right and doing a mouse-up. The purpose of this can be thought of as a safety feature, so the row can only be selected if the user drags the row to the right and lets go rather than just clicking on the row.
In order to implement this, I decided to create a new class that extends DropDownList (in Spark). I am stuck because I am not sure exactly what to do next. I was thinking of overriding an inherited event. I've been looking through AS 3.0 reference for DropDownList (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/DropDo wnList.html)
and I find a bunch of inherited events, but none that seem to fire when a selection is made.
I am not sure of a way to implement this, so I am trying different things out to no avail.
If anyone can shed some light onto this with any suggestions on how to implement this sort of DropDownList I would really appreciate it.
Hi,
Please refer to the following articles
To Create a Custom Field Type, you can refer to:
How
to: Customize a field type using client-side rendering
SharePoint 2013: Create custom Geolocation field type with client-side rendering
SharePoint
2013 Custom Field Type vs. Aggregation vs. XSLT list view vs. JSLink
How to: Create a User Control for
a SharePoint Application Page or Web Part
Adding
a custom control to a page with Design Manager
Please mark it answered, if your problem resolved.
Similar Messages
-
Flex 4: Custom ScrollBar not working in Custom DropDownList
Hello,
I'm having an odd issue that I just cannot figure out. I have a custom DropDownList .as component (to pass color values) and a custom skin. In this skin I am using a custom Scroller (same AS file component with mxml skin). When I use this configuration, clicking on the scrollbar just closes the DropDown. If I remove the skin from my custom scrollbar it works, which leads me to believe it has something to do with the DropDown skin. Even if I revert my custom Scroller to the spark Scroller, it still doesn't work. I've narrowed it down to what seems like a problem with my DropDownList skin.
Not really sure what code to put here, but all I've been doing is right clicking my project and making new ActionScript components and MXML skins from the default skin. Here is my DropDownList skin, not sure if I should paste any other code? I have no idea what would be causing this, so I don't really know what code to place.
[HostComponent("ccm.DropDown.DropDownList")]Woops, the code didn't place correctly, here it is:
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabled=".5" xmlns:Scroller="ccm.Scroller.*" xmlns:DropDown="ccm.DropDown.*">
<fx:Metadata>
[HostComponent("ccm.DropDown.DropDownList")]
</fx:Metadata>
<!-- host component -->
<fx:Script fb:purpose="styling">
<![CDATA[
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import mx.controls.Alert;
import spark.filters.*;
/* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
static private const contentFill:Array = [];
* @private
override public function get contentItems():Array {return contentFill};
* @private
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
openButton.setStyle("cornerRadius", getStyle("cornerRadius"));
super.updateDisplayList(unscaledWidth, unscaledHeight);
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="open" />
<s:State name="disabled" />
</s:states>
<!---
The PopUpAnchor control that opens the drop-down list.
<p>In a custom skin class that uses transitions, set the
<code>itemDestructionPolicy</code> property to <code>none</code>.</p>
-->
<s:PopUpAnchor id="popUp" displayPopUp.normal="false" displayPopUp.open="true" includeIn="open"
left="0" right="0" top="0" bottom="0" itemDestructionPolicy="auto"
popUpPosition="below" popUpWidthMatchesAnchorWidth="true" >
<!---
This includes borders, background colors, scrollers, and filters.
@copy spark.components.supportClasses.DropDownListBase#dropDown
-->
<s:Group maxHeight="134" minHeight="22" >
<s:Rect id="fill" left="1" right="1" top="1" bottom="0" bottomLeftRadiusX="16.5" bottomRightRadiusX="16.5" topLeftRadiusX="16.5" topRightRadiusX="16.5" >
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
<s:filters>
<s:GlowFilter
color="0x000000"
alpha=".35"
blurX="6"
blurY="6"
strength="1"
quality="{BitmapFilterQuality.HIGH}"
inner="true"
knockout="false"/>
</s:filters>
</s:Rect>
<!--- @private -->
<Scroller:Scroller id="scroller" left="8" top="8" right="8" bottom="8" hasFocusableChildren="false" minViewportInset="1"
showButtons="false"
trackColor="{hostComponent._trackColor}"
thumbColor="{hostComponent._thumbColor}"
skinClass="ccm.Scroller.ScrollerSkin">
<!--- @copy spark.components.SkinnableDataContainer#dataGroup-->
<s:DataGroup id="dataGroup" itemRenderer="ccm.DropDown.DropDownItemRenderer">
<s:layout>
<s:VerticalLayout gap="0" horizontalAlign="contentJustify"/>
</s:layout>
</s:DataGroup>
</Scroller:Scroller>
</s:Group>
</s:PopUpAnchor>
<!--- The default skin is DropDownListButtonSkin.
@copy spark.components.supportClasses.DropDownListBase#openButton
@see spark.skins.spark.DropDownListButtonSkin -->
<DropDown:DropDownButton id="openButton" left="0" right="0" top="0" bottom="0" focusEnabled="false"
skinClass="ccm.DropDown.DropDownButtonSkin"
buttonColor="{hostComponent._buttonColor}"
/>
<!--- @copy spark.components.DropDownList#labelDisplay -->
<s:Label id="labelDisplay" verticalAlign="middle" maxDisplayedLines="1"
mouseEnabled="false" mouseChildren="false"
left="12" right="30" top="2" bottom="2" width="75" verticalCenter="1" />
</s:SparkSkin> -
Creating Custom DropDownList FieldType in C#
Hi,
I need to create a custom dropdown list fieldtype in SharePoint 2013. I am new in SharePoint Development so need complete code step by step.Hi,
Please refer to the following articles
To Create a Custom Field Type, you can refer to:
How
to: Customize a field type using client-side rendering
SharePoint 2013: Create custom Geolocation field type with client-side rendering
SharePoint
2013 Custom Field Type vs. Aggregation vs. XSLT list view vs. JSLink
How to: Create a User Control for
a SharePoint Application Page or Web Part
Adding
a custom control to a page with Design Manager
Please mark it answered, if your problem resolved. -
Relationship between a Spark DropDownList's dataProvider and selectedItem
I'm working on an existing project and have come across a somewhat complicated issue regarding a Spark DropDownList's (actually, a custom component inheriting from it) displayed item not changing when its dataProvider is updated.
Here's the code for the custom TitleWindow component containing the custom DropDownList:
<?xml version="1.0" encoding="utf-8"?>
<components:RFTitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:components="components.*"
xmlns:rfform="rfform.*"
width="550" height="450"
title="{currentState} Site Equipment"
cancelButton="{btnCancel}"
defaultButton="{btnSave}"
initialFocus="{rftName}"
creationComplete="init()" close="cancelEdit()">
<fx:Script>
<![CDATA[
import events.SiteEquipmentEvent;
import events.SiteEquipmentTypeEvent;
import mx.collections.ArrayList;
import mx.controls.Menu;
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.events.MenuEvent;
import mx.managers.PopUpManager;
import mx.validators.ValidationResult;
import mx.validators.Validator;
import spark.events.IndexChangeEvent;
private const TYPES:Array = ["A", "B", "C", "D"];
[Bindable] [Embed(source="../assets/images/circle_red_x.gif")] private var icoRedX:Class;
[Bindable] private var siteEquipment:SiteEquipment;
private var validators:Array;
private var typePopUp:Menu;
public static function open(item:SiteEquipment):SiteEquipmentEdit
var s:SiteEquipmentEdit = new SiteEquipmentEdit();
s.siteEquipment = item;
PopUpManager.addPopUp(s, DisplayObject(FlexGlobals.topLevelApplication), true);
PopUpManager.centerPopUp(s);
return s;
private function init():void
initTypePopUp();
if (siteEquipment.id == SiteEquipment.NEW_ID)
currentState = "New";
else
currentState = "Edit";
validateAll();
if (!rftName.enabled)
rfcmbType.setFocus();
siteEquipment.addEventListener(SiteEquipmentEvent.SITE_EQUIPMENT_SAVE, saveComplete);
override public function dispose(event:Event = null):void
super.dispose();
siteEquipment.removeEventListener(SiteEquipmentEvent.SITE_EQUIPMENT_SAVE, saveComplete);
typePopUp.removeEventListener("itemClick", typePopUp_click);
siteEquipment.dispose();
icoRedX = null;
siteEquipment = null;
validators = null;
typePopUp = null;
removeChildren();
private function cancelEdit():void
siteEquipment.cancelEdit();
private function saveForm():void
var newValue:SiteEquipment = new SiteEquipment();
newValue.id = siteEquipment.id;
newValue.locid = siteEquipment.locid;
newValue.name = rftName.trimmedText;
siteEquipment.save(newValue);
private function saveComplete(event:Event):void
dispose();
private function typePopUp_click(event:MenuEvent):void
switch(event.item)
case "Edit Selected Type":
SiteEquipmentType(rfcmbType.selectedItem).showEditForm();
break;
case "Create A New Type":
new SiteEquipmentType().showEditForm(type_created, null, type_removeListeners);
break;
private function type_created(event:SiteEquipmentTypeEvent = null):void
type_removeListeners(event);
rfcmbType.selectedItem = event.siteEquipmentType;
private function type_removeListeners(event:Event):void
var s:SiteEquipmentType = SiteEquipmentType(event.target);
s.removeEventListener(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_CREATE, type_created);
s.removeEventListener(SiteEquipmentType.SITE_EQUIPMENT_TYPE_CANCEL, type_removeListeners);
private function initTypePopUp():void
typePopUp = Menu.createMenu(puType, ['Edit Selected Type', 'Create A New Type']);
typePopUp.addEventListener("itemClick", typePopUp_click);
private function popupTypeOptions():void
var p:Point = puType.localToGlobal(new Point(0, puType.height + 5));
typePopUp.show(p.x, p.y);
private function validateAll():void
var isValid:Boolean;
for each (var validator:Validator in validators)
isValid = true;
for each (var result:ValidationResult in validator.validate().results)
if (result.isError)
isValid = false;
break;
UIComponent(validator.source).styleName = "valid_" + isValid.toString();
private function rfcmbType_changeHandler(event:IndexChangeEvent):void
if (TYPES.indexOf(SiteEquipmentType(RFDropDownList(event.target).selectedItem).name) > -1)
rftName.text = "Blah";
rftName.enabled = false;
else
rftName.enabled = true;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:DateTimeFormatter id="mdy"
dateTimePattern="MM/dd/yyyy"/>
</fx:Declarations>
<components:states>
<s:State name="Edit"/>
<s:State name="New"/>
</components:states>
<rfform:RFForm width="100%" height="100%"
saveButton="{btnSave}"
validators="{new ArrayList([valQuantity, valHeight])}">
<rfform:RFFormItem label="Type"
width="100%">
<s:HGroup width="100%">
<rfform:RFDropDownList id="rfcmbType"
width="100%"
originalValue="{siteEquipment.model.eqType}"
dataProvider="{SiteEquipmentType.all}"
change="rfcmbType_changeHandler(event)"/>
<rfform:RFButton id="puType"
icon="@Embed(source='/Shared/src/assets/images/settings.png')"
width="30"
click="popupTypeOptions()"/>
</s:HGroup>
</rfform:RFFormItem>
</rfform:RFForm>
</components:RFTitleWindow>
I've omitted a little bit of code, so please ask if you need anything that I didn't include.
In regards to the RFDropDownList, originalValue is saved so that when a new selection is made, the new selection can be compared to the original value. Setting originalValue sets the RFDropDownList's selectedItem to originalValue.
When this window is first opened, a new instance of SiteEquipment is created. Unless the equipment is new, the SiteEquipment instance sets the SiteEquipmentType to whatever has already been saved, using this line:
eqType = SiteEquipmentType.selectFromObject(item.SITE_EQUIPMENT_TYPE);
And here's the code from the SiteEquipmentType class:
package components
import common.UpdateStatus;
import events.SiteEquipmentTypeEvent;
import scripts.MyUtility;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.setTimeout;
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.collections.SortField;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectProxy;
[Event(name="cacheChanged", type="flash.events.Event")]
[Event(name="SITE_EQUIPMENT_TYPE_CREATE", type="events.SiteEquipmentTypeEvent")]
[Event(name="SITE_EQUIPMENT_TYPE_EDIT", type="events.SiteEquipmentTypeEvent")]
[Event(name="SITE_EQUIPMENT_TYPE_CANCEL", type="flash.events.Event")]
public class SiteEquipmentType extends ObjectProxy
public static const NEW_ID:int = -1;
public static const SITE_EQUIPMENT_TYPE_CANCEL:String = "siteEquipmentTypeCancel";
[Bindable]
public var id:int = NEW_ID;
[DefaultProperty]
[Bindable]
public var name:String = "";
private static var dict:Object = new Object();
private static var getAllServiceCalled:Boolean = false;
private static var eventDispatcher:EventDispatcher = new EventDispatcher();
private var updateStatus:UpdateStatus = UpdateStatus.COMPLETE;
public function SiteEquipmentType(item:Object = null, keepInCache:Boolean = true)
if (item == null)
return;
else if (item is int)
id = int(item);
refreshFromDb();
else
updateFromResult(item);
if (keepInCache)
addToCache(this);
private static var _all:ArrayCollection = new ArrayCollection();
public static function get all():ArrayCollection
if (!getAllServiceCalled)
getAllServiceCalled = true;
MyUtility.httpPost("/page.aspx", {request:"SITE_EQUIPMENT_TYPE"}, getAll_result);
var s:Sort = new Sort();
s.fields = [new SortField("name", true)];
_all.sort = s;
return _all;
public static function addEventListener(type:String, listener:Function):void
eventDispatcher.addEventListener(type, listener);
public static function removeEventListener(type:String, listener:Function):void
eventDispatcher.removeEventListener(type, listener);
public static function dispatchEvent(event:Event):Boolean
return eventDispatcher.dispatchEvent(event);
private static function addToCache(item:SiteEquipmentType):void
removeFromCache(item.id);
dict[item.id] = item;
_all.addItem(item);
dispatchEvent(new Event("cacheChanged"));
private static function removeFromCache(id:int):void
var item:SiteEquipmentType = dict[id];
if (item)
delete dict[id];
_all.removeItemAt(_all.getItemIndex(item));
public static function selectById(id:int):SiteEquipmentType
if (dict[id])
return dict[id];
return new SiteEquipmentType(id);
public static function selectFromObject(obj:Object):SiteEquipmentType
var selected:SiteEquipmentType;
var objId:int = obj.SITE_EQUIPMENT_TYPE_ID;
if (dict[objId])
selected = dict[objId];
selected.updateFromResult(obj);
else
selected = new SiteEquipmentType(obj);
return selected;
private function updateFromResult(item:Object):void
if (item)
id = item.SITE_EQUIPMENT_TYPE_ID;
name = item.SITE_EQUIPMENT_TYPE_NAME;
private function toRequestObject():Object
var o:Object = new Object();
o.SITE_EQUIPMENT_TYPE_ID = id;
o.SITE_EQUIPMENT_TYPE_NAME = name;
return o;
public function copy():SiteEquipmentType
return new SiteEquipmentType(this.toRequestObject());
public function save(value:SiteEquipmentType):void
if (updateStatus == UpdateStatus.PENDING)
Alert.show("Site Equipment Type is pending an update.", "Pending Update");
return;
else if (updateStatus == UpdateStatus.ERROR)
Alert.show("There is a problem with this Site Equipment Type, and it cannot be saved. Please close the window.", "Save Failure");
return;
var request:Object;
if (id == NEW_ID)
if (value)
request = value.toRequestObject();
else
request = toRequestObject();
request._COMMAND = "INSERT";
else
if (value)
request = MyUtility.objectDiff(this.toRequestObject(), value.toRequestObject());
if (!request)
dispatchEvent(new SiteEquipmentTypeEvent(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_CREATE, this));
return;
else
request = toRequestObject();
request._COMMAND = "UPDATE";
request._SITE_EQUIPMENT_TYPE_ID = id;
delete request.SITE_EQUIPMENT_TYPE_ID;
updateStatus = UpdateStatus.PENDING;
MyUtility.httpPost("/updatetable.aspx?_SCHEMA=dbo&_TABLENAME=SITE_EQUIPMENT_TYPE&_RETURNRECORD=1", request, httpSave_result);
public function toString():String
return name;
public function refreshFromDb():void
if (updateStatus != UpdateStatus.PENDING)
updateStatus = UpdateStatus.PENDING;
MyUtility.httpPost("/page.aspx", {id:id, request:"Site_Equipment_Type"}, httpSelect_result);
public function showEditForm(onCreate:Function = null, onEdit:Function = null, onCancel:Function = null):void
if (id == 0)
Alert.show("Edits are not allowed on this Site Equipment Type.", "Not Allowed");
return;
if (onCreate != null)
addEventListener(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_CREATE, onCreate);
if (onEdit != null)
addEventListener(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_EDIT, onEdit);
if (onCancel != null)
addEventListener(SITE_EQUIPMENT_TYPE_CANCEL, onCancel);
if (updateStatus == UpdateStatus.PENDING)
setTimeout(showEditForm, 500);
else if (updateStatus == UpdateStatus.COMPLETE)
SiteEquipmentTypeEdit.open(this);
public function cancelEdit():void
dispatchEvent(new Event(SITE_EQUIPMENT_TYPE_CANCEL));
private static function getAll_result(event:ResultEvent):void
if (event.result.ROOT)
if (event.result.ROOT.ERROR)
Alert.show(event.result.ROOT.ERROR, "Error");
else
for each (var o:Object in MyUtility.ToArrayCollection(event.result.ROOT.SITE_EQUIPMENT_TYPE))
var i:SiteEquipmentType = dict[o.SITE_EQUIPMENT_TYPE_ID];
// If the Site Equipment Type is already in the cache, update it based on the XML returned
if (i)
i.updateFromResult(o);
// Otherwise, create a new one from the XML returned
else
i = new SiteEquipmentType(o);
_all.refresh();
private function httpSelect_result(event:ResultEvent):void
if (event.result.ROOT)
if (event.result.ROOT.ERROR)
Alert.show(event.result.ROOT.ERROR, "Error");
updateStatus = UpdateStatus.ERROR;
else
updateFromResult(event.result.ROOT.SITE_EQUIPMENT_TYPE);
updateStatus = UpdateStatus.COMPLETE;
else
updateStatus = UpdateStatus.ERROR;
private function httpSave_result(event:ResultEvent):void
if (event.result.ROOT.ERROR)
Alert.show(event.result.ROOT.ERROR, "Error");
updateStatus = UpdateStatus.ERROR;
else
try
updateStatus = UpdateStatus.COMPLETE;
if (id == NEW_ID)
id = event.result.ROOT.RESULTS.IDENTITY;
addToCache(this);
updateFromResult(event.result.ROOT["DBO.SITE_EQUIPMENT_TYPE"]);
dispatchEvent(new SiteEquipmentTypeEvent(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_CREATE, this));
else
updateFromResult(event.result.ROOT["DBO.SITE_EQUIPMENT_TYPE"]);
dispatchEvent(new SiteEquipmentTypeEvent(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_EDIT, this));
SiteEquipmentType.dispatchEvent(new SiteEquipmentTypeEvent(SiteEquipmentTypeEvent.SITE_EQUIPMENT_TYPE_EDIT, this));
catch(ex:Error)
Alert.show(ex.message, "Error");
updateStatus = UpdateStatus.ERROR;
So the "_all" ArrayCollection serves as a cache of all of the different site equipment types. When the edit window is first opened and a new instance of SiteEquipment is created, the SiteEquipmentType of the current SiteEquipment is added to _all and becomes the only SiteEquipmentType within _all.
At this point, the DropDownList has the correct item selected. The problem occurs when the result comes in from getting all of the SiteEquipmentTypes. The contents of _all are flushed, and each SiteEquipmentType is added in. Once this happens, the DropDownList will have nothing for selectedItem.
I know this is quite complex, but any help would be greatly appreciated.Ok, I have this figured out now. First, though, I'll point out that this worked fine when using MX components and the Halo theme; the problem only appeared after switching over to Spark components and the Spark theme. Anyway, since this class functions as a singleton (as best I understand them), I added a boolean variable to the SiteEquipmentType class representing whether or not the results from the HTTPService call had come back and been inserted into _all. So in the TitleWindow's init method, I only populated the DropDownList's originalValue (which in turn sets the selectedItem) if that variable is true. The first time an instance of the TitleWindow component is opened, though, this variable will initially be false. So back in the SiteEquipmentType class, I have it dispatch an event right after setting the variable to true, and the TitleWindow componet will add a listener for this event if the variable is originally false. If anyone needs further explanation, please ask.
-
How to make requestedRowCount work?
I am using this and it's not doing what I want.
<s:DropDownList id="ddlData" dataProvider="{parentApplication.acData}" labelField="name" prompt="Select" selectedIndex="-1" width="150">
<s:layout>
<s:VerticalLayout gap="0" horizontalAlign="contentJustify" requestedRowCount="11"/>
</s:layout>
</s:DropDownList>
What am I doing wrong please?Just to clarify for better help, you want 11 rows of data to be displayed when using the dropdown list?
From Flex Examples
There is a slight “gotcha” when trying to set the requestedRowCount property >=6 . The default Spark DropDownListSkin sets a max height for the dropdown to 134px — which is roughly a requestedRowCount of 6 (unless the drop down menu has a horizontal scroll bar in which case the bottom item renderer is somewhat obscured by the horizontal scroll bar).
If you want to set the requested row count to higher than 5-6, you need to either create a custom DropDownList skin and remove the specified maxHeight (line 114 — as of 4.0.0.13895) or you can programmatically set the default DropDownListSkin drop down rowHeight property to NaN (Not a Number). For more information seehttp://bugs.adobe.com/jira/browse/SDK-25364.
This bug report shows a perfect example of this:
http://bugs.adobe.com/jira/browse/SDK-25364 -
DropDownList as a custom renderer
Any idea how to create a custom renderer based on DropDownList for dataGrid?
ThanksI'm sorry but that went a little over my head, could you point me in the direction of an example, alternativly I have extracted the following example from my application showing what I have so far. If I skin my ItemRenderer for the DropDownList, I'm worried it will upset the ItemRenderer for each of the items in the list!
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)"
viewSourceURL="srcview/index.html">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
protected var acArrayCollection:ArrayCollection = new ArrayCollection();
protected function application1_creationCompleteHandler(event:FlexEvent):void
var obj:Object;
for (var i:int = 0; i<10; i++)
obj = new Object();
obj.idx1 = i;
obj.item = i;
obj.idx2 = i;
acArrayCollection.addItem(obj);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:DataGrid x="10" y="10" dataProvider="{acArrayCollection}" editable="true">
<mx:columns>
<mx:DataGridColumn headerText="" dataField="idx1" width="50" editable="false" textAlign="center"/>
<mx:DataGridColumn headerText="DataGridColumn" dataField="item" width="260"
itemRenderer="itemRenderer.IRDropDownList" rendererIsEditor="true"
editorDataField="selectedItem"/>
<mx:DataGridColumn headerText="" dataField="idx2" width="50" editable="false" textAlign="center"/>
</mx:columns>
</mx:DataGrid>
</s:Application>
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<fx:Script>
<![CDATA[
import mx.events.DragEvent;
import spark.events.DropDownEvent;
import spark.events.IndexChangeEvent;
[Bindable]
public var selectedItem:int;
protected function dropdownlist1_changeHandler(event:IndexChangeEvent):void
selectedItem = dropDown.selectedIndex;
override public function set data(value:Object):void
super.data = value;
selectedItem = value.item;
]]>
</fx:Script>
<s:DropDownList id="dropDown" left="3" right="3" width="100%"
itemRenderer="itemRenderer.IRLabel"
selectedIndex="{selectedItem}"
change="dropdownlist1_changeHandler(event)">
<s:dataProvider>
<s:ArrayCollection>
<fx:String>Option 1</fx:String>
<fx:String>Option 2</fx:String>
<fx:String>Option 3</fx:String>
<fx:String>Option 4</fx:String>
<fx:String>Option 5</fx:String>
<fx:String>Option 6</fx:String>
<fx:String>Option 7</fx:String>
<fx:String>Option 8</fx:String>
<fx:String>Option 9</fx:String>
<fx:String>Option 10</fx:String>
<fx:String>Option 11</fx:String>
<fx:String>Option 12</fx:String>
</s:ArrayCollection>
</s:dataProvider>
</s:DropDownList>
</s:MXDataGridItemRenderer>
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<fx:Script>
<![CDATA[
[Bindable]
public var bgColor:int;
[Bindable]
public var myHoverColor:int;
[Bindable]
public var mySelectColor:int;
[Bindable]
public var myColor:int;
override public function set itemIndex(value:int):void {
super.itemIndex = value;
if ((value%2) == 0) {
bgColor= 0xFFFFFF;
if ((value%2) == 1) {
bgColor= 0xE0E0E0;
override public function set data(value:Object):void
super.data = value;
if (value == "Option 5")
labelDisplay.setStyle("color","#FFFFFF");
bgColor = 0x808080;
myHoverColor = 0x808080;
mySelectColor = 0x808080;
myColor = 0xFFFFFF;
labelDisplay.left = 3;
else
labelDisplay.setStyle("color","#000000");
//myBackColor = 0xFFFFFF;
myHoverColor = 0x5050A0;
mySelectColor = 0x7070C0;
myColor = 0x000000;
labelDisplay.left = 13;
]]>
</fx:Script>
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="selected" />
</s:states>
<s:Rect id="bgRect"
includeIn="normal,hovered,selected"
left="0" right="0" top="0" bottom="0">
<s:fill>
<s:SolidColor
color = "{bgColor}"
color.selected="{mySelectColor}"
color.hovered="{myHoverColor}"/>
</s:fill>
</s:Rect>
<s:Label id="labelDisplay"
color="{myColor}"
right="3" top="4" bottom="3"/>
</s:ItemRenderer> -
How do I get a web part to display items from a dropdownlist?
I have a DropDownList that am filling with items from a list. The part of my code that am using to read the list and populating the drop down works just fine. I am now trying to figure out how to display the contents of the drop down on a web part. I know
it sounds like a straight forward and easy thing to figure out, but I have blanked out. Does anyone have a snippet I can take a look at? This is how I am currently reading from a list to create the drop down...
protected override void CreateChildControls()
string title = string.Empty;
EditorChoices = new DropDownList();
string siteUrl = "mySite";
using (SPSite site = new SPSite(siteUrl))
SPWeb web = site.RootWeb;
SPList list = web.Lists["testList"];
SPQuery testQuery = new SPQuery();
testQuery.Query = "<Query><Where><Geq><FieldRef Name='Title'/>" +
"<Value Type='Number'>10</Value></Geq></Where></Query>";
foreach (SPListItem item in list.GetItems(testQuery))
title = Convert.ToString(item["Title"]);
EditorChoices.Items.Add(title);
Controls.Add(EditorChoices);
base.CreateChildControls();
ChildControlsCreated = true;
I basically want to display the items returned from the query, which are now in the dropdownlist, to be displayed on my custom webpart. I really appreciate the help.
Thanks
UPDATE: My dropdownlist is a web part property. So when editing the web part, the drop down control appears in the web part property. Now that part is working just fine. The part am having an issue with is, the second part of my requirement is that I want
to display that same information within the drop down on the web part. Not as another drop down, but just to display them as a vertical text list on the web part.Hello,
>I want to be able to display all the entteries in the dropdown,
Could you please provide more information? as per your description fisrt part is done, which was filling data in dropdown list. So what is next?
If you want to get selected value from dropdown or filter value then you may try this link:
http://bilbrobloggins.com/sharepoint/dropdown-list-box-filter-web-part-in-sharepoint-ndash-part-three/
http://tmullenssharepoint.wordpress.com/2013/04/12/sharepoint-custom-web-part-properties-from-sharepoint-list/
Correct me if i misunderstood
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
Problem in using custom java beans
Hi,
We are using oracle JDeveloper 3.2.2 version for developing our Graphical User interface which
involves Applets and custom beans.
We faced the following problems when we tried to add the custom beans to JApplet.
Problem 1. When I drag and drop the custom beans to JApplet, the gif image used by the bean is
not displayed even when the gif image has been added in the archive file representing
JavaBean
Problem 2. When I modify the source code generated by Jdeveloper and come back to the design tab,
the custom beans looses its look and feel and gets the look and feel of the standard
bean from which it has been extended.
For instance, I have a dropdownlist which has been extended from JCombobox.
I drag and drop to the JApplet. The look and feel of the dropdownlist is
maintained.
Now I modify the source code for the dropdownlist in order to add items to it.
After doing so, I come back to the design tab where i can see my dropdownlist
appears with the look and feel of JCombobox.HI,
IF YOU create custom object the profile should be the same as standard.Also see whether the authorization object is added to the data target or not.
Hope this helps
Assign points if useful
Regards,
venkat -
Using itemCreationPolicy with a custom component
I'm working on a project where the users need to be able to have a 'filtered' view of one of the edit dialogs. I'm using view states to control which of the input fields show up for each view. The 'save' logic is the same for both states, so I still need to be able to pull data for the inputs even if they are not currently displayed. I tried setting itemCreationPolicy to immediate with no success. Some of the inputs were getting created but the initial values were not being set. The issue seems to be that the input component (an extended version of DropDownList) defers setting the selected value until the commitProperties() method. Since the inpit isn't actually being shown, the commitProperties() method is never getting called and the value is never being set.
Can anyone suggest a workaround for this issue? The only thing I can think of would be to use includeInLayout and visible to show/hide the inputs, but that is going to get really messy since I would have to apply it to every input and the FormItem components that enclose them.Jasmin,
Is your class included in the custom component?
Yes, It is a annotated entity class,
When creating sessionFactory it is not loading the class.
i'm using flowing code block for creating sessionFactory,
factory =
new AnnotationConfiguration().addAnnotatedClass(dao.entity.UserEntity.
class).setProperty(
"hibernate.dialect",m_dialect ).setProperty(
"hibernate.connection.driver_class", m_driverClass).setProperty(
"hibernate.connection.url", m_connectionUrl ).setProperty(
"hibernate.connection.username",m_userName).setProperty(
"hibernate.connection.password", m_password).setProperty(
"hibernate.hbm2ddl.auto", m_hbmTodll ).setProperty(
"current_session_context_class",m_contextClass ).configure(resource).buildSessionFactory();
Is the jar referenced in the class patch section of the component.xml?
Yes , I have tried for this approch too , but class is entity class is not loaded. -
Issue in rendering CustomToolpart to select data source for custom webpart..
I have a custom webpart in which i have added a tool part.This toolpart should allow me to select any list in the sitecollection which would be displayed on the webpage on doing apply in the webpart properties.The dropdown list with all lists is coming fine.The
grid is diplaying as well.But in the toolpart,not in the webpart. I cant seem to segregate the two.There is also a textbox in the toolpart in which the entered text comes in the webpart.But the same approach is failing for the gridview.Please suggest
what to do.
Also,i am failing at making a separate category for the toolpart by specifying [category("List settings")]..Any suggestion as to what i'm doing wrong in that are welcome too.
Here is my webpart class and toolpart class.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Data;
using Microsoft.SharePoint.Utilities;
namespace BB.WorkSpaces.Common.WebParts.CustomList
[ToolboxItemAttribute(false)]
public class CustomList : Microsoft.SharePoint.WebPartPages.WebPart
[Browsable(false),
Category("List Settings"),
Description("Text Property")]
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/BB.WorkSpaces.Common.WebParts/CustomList/CustomListUserControl.ascx";
public string ListName
get
return _listName;
set
_listName = value;
string _listName;
public string ListValue
get
return _listValue;
set
_listValue = value;
string _listValue;
public GridView Gv
get { return gv; }
set { gv = value; }
GridView gv;
protected override void Render(HtmlTextWriter writer)
base.Render(writer);
writer.Write(ListName);
writer.Write("<br />");
writer.Write(ListValue);
writer.Write("<br />");
writer.Write(Gv);
public override ToolPart[] GetToolParts()
ToolPart[] allToolParts = new ToolPart[3];
WebPartToolPart standardToolParts = new WebPartToolPart();
CustomPropertyToolPart customToolParts = new CustomPropertyToolPart();
allToolParts[0] = standardToolParts;
allToolParts[1] = customToolParts;
allToolParts[2] = new CustomToolPart();
return allToolParts;
public class CustomToolPart : Microsoft.SharePoint.WebPartPages.ToolPart
DropDownList ddl;
TextBox tb;
protected override void CreateChildControls()
ddl = new DropDownList();
ddl.ID = "ddl";
// Simply getting the lists of the current web, and displaying them in the dropdown-list.
SPListCollection lists = SPContext.Current.Web.Lists;
foreach (SPList list in lists)
ddl.Items.Add(list.Title);
tb = new TextBox();
tb.ID = "tb";
Controls.Add(ddl);
Controls.Add(tb);
base.CreateChildControls();
public override void ApplyChanges()
CustomList wp = (CustomList)this.ParentToolPane.SelectedWebPart;
wp.ListName = ddl.SelectedValue;
wp.ListValue = tb.Text;
SPSite site = SPContext.Current.Site;
SPWeb web = site.RootWeb;
SPList list = web.Lists[ddl.SelectedItem.Text];
//SPListItemCollection slist = list.GetItems();
GridView GV1 = new GridView();
DataTable dt = list.Items.GetDataTable();
GV1.DataSource = dt;
GV1.DataBind();
this.Controls.Add(GV1);Hi,
According to your post, my understanding is that you have an issue about the custom web part.
Per my knowledge, we should customize the EditorPart instead of the
ToolPart to bind the lists to the dropdown list.
There is a good article about customizing web part, you can refer to it.
http://www.concurrency.com/blog/create-a-custom-web-part-for-sharepoint-2010/
More reference:
http://www.enjoysharepoint.com/Articles/Details/show-all-list-in-dropdown-list-using-visual-web-part-20676.aspx
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support -
Display a message when an item is selected from a dropdownlist
Hi,
I need to display a message(kind of alert message) when certain items are selected from the dropdownlist.
Let me know what is a good way to do this in web elements?
Thankshello,
unfortunately there is no validation / alerting for select menus in webelements.
however...if you're feeling ambitious and or this is a definite requirement for your project...custom functions are open source so you could write an on change javascript function within the WESelect custom function that will find the new value and compare it against your certain items array of values.
out of curiosity, what is your project's particular need to have an alert for a select menu based on what the end user selects? if this comes up more often or there's a good use case perhaps this could be built into a future version.
jw -
Problem with this version of DropDownLists, there is no removeItem function
Dear All,
I have a problem with this new version of the DropDownLists, in previous versions you had the removeItem function and others, but now you just have clearItems and addItem.
I have a list of elements in which a customer will be able to link and delete any element that he wants, I had selected a DropDownList to do that but considering that the removeItem function is not present I dont know how to do that...
Does anybody know how to delete a element in a dropdownlist?
If not, the solution will be to get all the elements in an array and reload the list but without the element "deleted" . Does anybody knows how to get all the elements of a DropDownList?
Thanks
Ruben.If you have a drop-down list named myDropDownList,with SOMExpression
Form.page1.myDropDownList then you can remove the
element at position
i using the following code:
var myItems = xfa.form.resolveNode("Form.page1.myDropDownList.#items");
myItems.nodes.remove(myItems.nodes.item(i));
Good luck. -
hi,
I have created a custom list in my sharepoint :
List1 name: employeedepartment -
Title empdepartment
A D1
B D2
C D3
List2 name: employeedetails
emptitle empname empdepartment(lookup) --> from the list "employeedepartment"
x Ram D1
y Robert D2
z Rahim D3
My task is to create a custom webpart that will be for searching this employee details by entering emptitle
For this, i have created a visual webpart using visual studio 2010, my webpart will be like this:
emptitle ---> TextBox1 Button1--> Text property : Search
empname---> TextBox2
empdepartment--> DropDownList1
For this, i wrote the code as follows:
protected void Button1_Click(object sender, EventArgs e)
using (SPSite mysite = new SPSite(SPContext.Current.Site.Url))
using (SPWeb myweb = mysite.OpenWeb())
SPList mylist = myweb.Lists["employeedetails"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + TextBox1.Text.ToString() + "</Value></Eq></Where>";
SPListItemCollection myitems = mylist.GetItems(query);
if (myitems.Count > 0)
foreach (SPListItem item in myitems)
string a1 = Convert.ToString(item["empname"]);
string a2 = Convert.ToString(item["empdepartment"]);
TextBox2.Text = a1; // displaying properly
//DropDownList3.SelectedIndex = 1;
It is showing the list item in textbox according to the item entered in the textbox1... But I am stuck to show in the dropdown list.
Suppose, if i enter X in textbox and click on search, then dropdownlist need to show D1,
for Y --> D2 and for Z-> D3... like that.
What code do i need to write in the button_click to show this...
Please don't give any links...i just want code in continuation to my code.Hi,
Since you have got the data you want with the help of SharePoint Object Model, then you can focus on how to populate values and set an option selected in the Drop Down List.
With the retrieved data, you can populate them into the Drop Down List firstly, then set a specific option selected.
Here is a link will show how to populate DropDownList control:
http://www.dotnetfunda.com/articles/show/30/several-ways-to-populate-dropdownlist-controls
Another link about select an item in DropDownList:
http://techbrij.com/select-item-aspdotnet-dropdownlist-programmatically
Best regards
Patrick Liang
TechNet Community Support -
Cannot have multiple items selected in a DropDownList when edit the forum in sharepoint
hi ,
i have custom forum for new and edit, in new forum we have controls drop down values, when select drop down1 values that related values are displayed in dropdown2 , when edit item that time we getting error
Cannot have multiple items selected in a DropDownList.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
Source Error:
HttpException (0x80004005): Cannot have multiple items selected in a DropDownList.]
System.Web.UI.WebControls.DropDownList.VerifyMultiSelect() +124
System.Web.UI.WebControls.ListControl.RenderContents(HtmlTextWriter writer) +10956501
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +13
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
ASP._controltemplates_amat_appayrequest_webparts_appayrequest_appayrequestusercontrol_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES\AMAT.APPayRequest.Webparts\APPayRequest\APPayRequestUserControl.ascx:350
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +115
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +253
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +87
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +53
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +42
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +240
System.Web.UI.Page.Render(HtmlTextWriter writer) +38
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4240Hello,
Could you please share your code with us? Also explain how you are binding DDL.
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
In edit mode in gridview everytime ihave to select dropdownlist otherwise its store first value
<asp:GridViewID="GVTrouserJobWork"runat="server"
AutoGenerateColumns="False"CssClass="Gridview"HeaderStyle-BackColor="#4B6D9D
"DataKeyNames="TrouserJobID"
OnRowCancelingEdit="GVTrouserJobWork_RowCancelingEdit"OnRowDeleting="GVTrouserJobWork_RowDeleting"
OnRowEditing="GVTrouserJobWork_RowEditing"OnRowUpdating="GVTrouserJobWork_RowUpdating">
<Columns>
<asp:TemplateFieldHeaderText="StyleNo"
<asp:LabelID="lblStyleNo"runat="server"Text='<%#Eval("StyleNo")
%>'/>
<asp:DropDownList Width="60px" DataSource='<%# GetStyleNo() %>' DataTextField="StyleNo"
DataValueField="StyleNo" ID="StyleNo"
runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:LabelID="lblStyleNo1"runat="server"Text='<%#Eval("StyleNo")
%>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public
DataSetGetStyleNo() {
SqlConnectionmyConnection =
newSqlConnection(ConfigurationManager.ConnectionStrings["constring"].ToString());
SqlCommandcmd =
newSqlCommand();
cmd.Connection = con;
cmd.CommandText =
"StleMasterList";
cmd.CommandType =
CommandType.StoredProcedure;
SqlDataAdapterad =
newSqlDataAdapter("StleMasterList",
myConnection);
//SelectDDCompanyName
DataSetds =
newDataSet();
ad.Fill(ds,
"StleMasterList");
return
ds;
StleMasterList = Select StyleNo from Stylemaster
protectedvoid
GVTrouserJobWork_RowUpdating(objectsender,
GridViewUpdateEventArgse)
intTrouserOrderID =
Convert.ToInt32(GVTrouserOrderDetail.DataKeys[e.RowIndex].Value.ToString());
DropDownListStyleNo = (DropDownList)GVTrouserOrderDetail.Rows[e.RowIndex].FindControl("StyleNo");
SqlCommandcmd =
newSqlCommand("update
TrouserOrders set StyleNo='"+
StyleNo.SelectedValue.ToString() + "'where
TrouserOrderID="+ TrouserOrderID, con);
cmd.ExecuteNonQuery();
con.Close();
lblresult.ForeColor =Color.Green;
lblresult.Text = " Details Updated successfully";
GVTrouserOrderDetail.EditIndex = -1;
BindTrouserOrderDetails();
Actually I get dropdown in editmode but when without selecting dropdownlist if I update it it select first value of dropdown list.
if have two dropdownlist in gridview and I want to update only one I cant do this every time I have to select both
dropdownlist .Hello Fresherss,
I think the ASP.NET forum will be more suitable for this thread:
http://forums.asp.net/
There are ASP.NET experts who will help you better.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Maybe you are looking for
-
I plugged my ipod in the computer and it's like a didn't plugg any thing in at all. what should I do?
-
When I go to publish my file in html I get an error message: "Error creating SWF movie file. Be sure the destination file is not locked or on a locked drive. Also, check that the file name is not too long" I've done all of the above and still get the
-
Hey! Could anyone help med with this prob: I' m trying to create a linked list. Say I have a list of 5 elements in my linked list, and now I want to add another element in position nr 3 and move the following elements. How do I do? I tried in this wa
-
Just bought a new Imac 21". I tried to answer my question from the video tutorial.....but the version of I photo on the video is different to the one on my computer! How do you re-size photos you want to send by email? When i click on share then emai
-
Hello, Can anyone guide me how to learn BI Publisher from begining and provide me some study material as well ? My email id is [email protected] Thanks n Regards, Mrugesh Parikh