进入各选择控件的interactivechang中写入:
da=[]
if thisformcheck1value=1
da=da+[A]
endif
if thisformcheck2value=1
da=da+[B]
endif
if thisformcheck3value=1
da=da+[C]
endif
if thisformcheck4value=1
da=da+[D]
endif
下面再将da变量换入答案字段
没法从后台直接获取前台extjs树上的情况。但是可以从前台获取树选中的情况,传给后台,后台就知道了~~~ 前台获取选中树的节点的方法: 方法1在树上做个listeners,监听树的click事件(在click中选中节点),或者监听节点的checkchange事件
实现这个其实很简单这只是一个思路问题,目的就是已经有N(指定数量)被勾选后再选择就提示并不让选择,方法可以有很多种,可以弄一个变量或一个隐藏域来存储已选值(这样可以提高检查时的速度)如:
以下值记录在checkbox的container元素上的checkboxValue属性上,如果有初始化值直接写上(以半角,号隔开)
<div id="checkboxContainer" checkboxValue="">
<input name="ck" type=checkbox value=1 onclick="return checkValue(this);;">1
<input name="ck" type=checkbox value=2 onclick="return checkValue(this);;">2
<input name="ck" type=checkbox value=3 onclick="return checkValue(this);;">3
<input name="ck" type=checkbox value=4 onclick="return checkValue(this);;">4
<input name="ck" type=checkbox value=5 onclick="return checkValue(this);;">5
<input name="ck" type=checkbox value=6 onclick="return checkValue(this);;">6
<input name="ck" type=checkbox value=7 onclick="return checkValue(this);;">7
<input name="ck" type=checkbox value=8 onclick="return checkValue(this);;">8
<input name="ck" type=checkbox value=9 onclick="return checkValue(this);;">9
<input name="ck" type=checkbox value=10 onclick="return checkValue(this);;">10
</div>
<script>
function checkValue(ck){
var cn = documentgetElementById("checkboxContainer");
var v = cngetAttribute("checkboxValue");
var vs = v==""[]:vsplit(",");
if(!ckchecked){//如果是checked说明是取消选择
vssplice(vsindexOf(ckvalue),1);
}else{
if(vslength>=3){
alert("只能选择最多3项!");return false;
}
vspush(ckvalue);
}
cnsetAttribute("checkboxValue",vsjoin(","));
return true;
}
</script>
在 Properties 的 OnEditValueChanged 事件写代码:
将当前行的主键值记录下来
Qry过滤,Filter := 'Check字段 =True'
将过滤出来的记录 Check字段 全部修改为 False
根据第1步记录的主键值,定位回修改的那行,并将其 Check字段 修改为 True
大致代码如下
vartmpKey: string;
begin
if not qryFieldByName('Check字段')AsBoolean then
Exit;
tmpKey := qryFieldByName('key字段')AsString;
qryDisableControls;
try
qryFiltered := False;
qryFilter := 'Check字段 =True';
qryFiltered := True;
while not qryIsEmpty then
begin
qryEdit;
qryFieldByName('Check字段')Value := False;
qryPost;
end;
qryLocate('key字段', tmpKey, []);
qryEdit;
qryFieldByName('Check字段')Value := True;
qryPost;
finally
qryEnableControls;
end;
end;
你的gruopBox1里还有其他的控件,比如Button,所以你直接这样写是不行的,需要加一个判断,把foreach那段修改成下面吧:
foreach (Control control in groupBox1Controls) //这里是Control,不是CheckedListBox{
if (control is CheckedListBox) //这里加一个判断,控件是否是CheckedListBox
{
arrChkInfoAdd(controlSelectedValue);
}
}
treeView1有个属性是CheckBoxes
using System;
using SystemDrawing;
using SystemWindowsForms;
public class Form1 : Form
{
private TreeView treeView1;
private Button showCheckedNodesButton;
private TreeViewCancelEventHandler checkForCheckedChildren;
public Form1()
{
treeView1 = new TreeView();
showCheckedNodesButton = new Button();
checkForCheckedChildren =
new TreeViewCancelEventHandler(CheckForCheckedChildrenHandler);
thisSuspendLayout();
// Initialize treeView1
treeView1Location = new Point(0, 25);
treeView1Size = new Size(292, 248);
treeView1Anchor = AnchorStylesTop | AnchorStylesLeft |
AnchorStylesBottom | AnchorStylesRight;
treeView1CheckBoxes = true;
// Add nodes to treeView1
TreeNode node;
for (int x = 0; x < 3; ++x)
{
// Add a root node
node = treeView1NodesAdd(StringFormat("Node{0}", x4));
for (int y = 1; y < 4; ++y)
{
// Add a node as a child of the previously added node
node = nodeNodesAdd(StringFormat("Node{0}", x4 + y));
}
}
// Set the checked state of one of the nodes to
// demonstrate the showCheckedNodesButton button behavior
treeView1Nodes[1]Nodes[0]Nodes[0]Checked = true;
// Initialize showCheckedNodesButton
showCheckedNodesButtonSize = new Size(144, 24);
showCheckedNodesButtonText = "Show Checked Nodes";
showCheckedNodesButtonClick +=
new EventHandler(showCheckedNodesButton_Click);
// Initialize the form
thisClientSize = new Size(292, 273);
thisControlsAddRange(new Control[]
{ showCheckedNodesButton, treeView1 } );
thisResumeLayout(false);
}
[STAThreadAttribute()]
static void Main()
{
ApplicationRun(new Form1());
}
private void showCheckedNodesButton_Click(object sender, EventArgs e)
{
// Disable redrawing of treeView1 to prevent flickering
// while changes are made
treeView1BeginUpdate();
// Collapse all nodes of treeView1
treeView1CollapseAll();
// Add the checkForCheckedChildren event handler to the BeforeExpand event
treeView1BeforeExpand += checkForCheckedChildren;
// Expand all nodes of treeView1 Nodes without checked children are
// prevented from expanding by the checkForCheckedChildren event handler
treeView1ExpandAll();
// Remove the checkForCheckedChildren event handler from the BeforeExpand
// event so manual node expansion will work correctly
treeView1BeforeExpand -= checkForCheckedChildren;
// Enable redrawing of treeView1
treeView1EndUpdate();
}
// Prevent expansion of a node that does not have any checked child nodes
private void CheckForCheckedChildrenHandler(object sender,
TreeViewCancelEventArgs e)
{
if (!HasCheckedChildNodes(eNode)) eCancel = true;
}
// Returns a value indicating whether the specified
// TreeNode has checked child nodes
private bool HasCheckedChildNodes(TreeNode node)
{
if (nodeNodesCount == 0) return false;
foreach (TreeNode childNode in nodeNodes)
{
if (childNodeChecked) return true;
// Recursively check the children of the current child node
if (HasCheckedChildNodes(childNode)) return true;
}
return false;
}
}
以上就是关于我在vfp中设置了多选题,用几个check控件作为答案选择全部的内容,包括:我在vfp中设置了多选题,用几个check控件作为答案选择、ext js 请教各位,怎样读取 单选/多选框的值、如何用asp实现checkbox多选等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)