2006/04/20 | DG右键选定
类别(网摘) | 评论(0) | 阅读(27) | 发表于 05:54
网摘:http://www.darronschall.com/weblog/archives/000088.cfm

// on stage: info_dg - datagrid, status_txt - dynamic text

// create a context menu
var cm:ContextMenu = new ContextMenu();
cm.hideBuiltInItems();
// add "delete item" to the menu - "delete" won't work as a label
cm.customItems.push(new ContextMenuItem("Delete Item", onDeleteSelected));

// called when "Delete Item" is selected in the data grid
function onDeleteSelected() {
  // trick the datagrid into thinking the mouse was released so that
  // moving the mouse doesn't scroll the grid
  info_dg.onMouseUp();
  
  // display a message
  status_txt.text = "You chose to delete:" + info_dg.selectedItem.item;
}

// called before the context menu is first displayed
cm.onSelect = function(info_dg) {
  // select the "lastOver" row when we right-click, but only
  // if it is not already selected
  if (info_dg.selectedIndex - info_dg.vPosition != info_dg.lastOver) {
    info_dg.onRowPress(info_dg.lastOver);
    
  }
}

// called when a row is rolled over
itemRollOver = change = function(eventObj) {
  // get the index of rolled over row, and adjust for scroll position
  // if the datagrid was scrolled vertically. store it in a "lastOver"
  // variable

  // change uses selectedIndex, itemRollOver uses index
  var tmpIndex;
  if (eventObj.type == "change") {
    tmpIndex = eventObj.target.selectedIndex;
  } else {
    tmpIndex = eventObj.index;
  }
  eventObj.target.lastOver = tmpIndex - eventObj.target.vPosition;
}

// update the lastOver row when the selected row changes or when
// a row is rolled over
info_dg.addEventListener("change", this);
info_dg.addEventListener("itemRollOver", this);

// add some data
office_items = ["Stapler", "Rubber Band", "Thumb Tack", "Notebook", "Pen", "Pencil", "Phone"];
my_dp = new Array();
for (var i = 0; i < office_items.length; i++) {
  my_dp.push({item:office_items[i]});
}
info_dg.dataProvider = my_dp;

// set up the context menu
info_dg["menu"] = cm;
0

评论Comments

日志分类
首页[28]
flash[3]
javascript[3]
C#[1]
feeling[5]
网摘[16]