- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我做了一个扩展方法来交换 CheckedListBox 中两个项目的位置。该方法放在静态 Utilities 类中。问题是 CheckState 不会移动。因此,如果我在列表中向上移动一个选中的项目,复选框状态将保持不变,移动的项目将接管它正在替换的项目的 CheckState。
我的代码是这样的:
public static System.Windows.Forms.CheckedListBox.ObjectCollection Swap(this System.Windows.Forms.CheckedListBox.ObjectCollection lstBoxItems, int indexA, int indexB)
{
if (indexB > -1 && indexB < lstBoxItems.Count - 1)
{
object tmpItem = lstBoxItems[indexA];
lstBoxItems[indexA] = lstBoxItems[indexB];
lstBoxItems[indexB] = tmpItem;
}
return lstBoxItems;
}
我想要的是这样的东西(显然行不通)
public static System.Windows.Forms.CheckedListBox.ObjectCollection Swap(this System.Windows.Forms.CheckedListBox.ObjectCollection lstBoxItems, int indexA, int indexB)
{
if (indexB > -1 && indexB < lstBoxItems.Count - 1)
{
object tmpItem = lstBoxItems[indexA];
System.Windows.Forms.CheckState state = tmpItem.CheckState;
lstBoxItems[indexA] = lstBoxItems[indexB];
lstBoxItems[indexB] = tmpItem;
}
return lstBoxItems;
}
代码简单这样调用
myCheckedListBox.Items.Swap(selectedIndex, targetIndex);
最佳答案
我以前没有使用过 CheckedListBox
,但如果我不得不冒险猜测一下它的 MSDN 文档,我会说你会想使用 GetItemCheckedState和 SetItemCheckedState方法。但是,这也意味着您还必须传入 CheckedListBox
而不仅仅是它的 .Items
ObjectCollection
。
public static System.Windows.Forms.CheckedListBox Swap(this System.Windows.Forms.CheckedListBox listBox, int indexA, int indexB)
{
var lstBoxItems = listBox.Items;
if (indexB > -1 && indexB < lstBoxItems.Count - 1)
{
System.Windows.Forms.CheckState stateA = listBox.GetItemCheckState(indexA);
System.Windows.Forms.CheckState stateB = listBox.GetItemCheckState(indexB);
object tmpItem = lstBoxItems[indexA];
lstBoxItems[indexA] = lstBoxItems[indexB];
lstBoxItems[indexB] = tmpItem;
listBox.SetItemCheckState(indexA, stateB);
listBox.SetItemCheckState(indexB, stateA);
}
return listBox;
}
所以你的调用代码自然会变成这样:
myCheckedListBox.Swap(selectedIndex, targetIndex);
另请注意,我的方法也返回输入 CheckedListBox
而不是 ObjectCollection
;考虑到签名参数的变化,现在认为这会更合适。
关于c# - 在静态方法中获取项目 CheckState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17260137/
PyQt6 文档说 Qt.CheckState.Unchecked == 0 和 Qt.CheckState.Checked == 2。 我写了一个小程序来测试这一点,但结果完全不同。 程序代码如下:
我做了一个扩展方法来交换 CheckedListBox 中两个项目的位置。该方法放在静态 Utilities 类中。问题是 CheckState 不会移动。因此,如果我在列表中向上移动一个选中的项目,
使用 checkState 相对于断言有什么好处吗?我记得在某处读过我应该更喜欢 checkState 但我不记得为什么。 最佳答案 checkState 和 assert 具有完全不同的目的。 ch
我有一堂这样的课: public class TimerActivity extends Activity { CountDownTimer cntTimer = null; @Override pr
我想在 QSetting 中保存 QCheckBok 的状态,我可以将它的值转换为 int 但也许存在更简单和适当的方法来做到这一点? 这是我的代码: QSetting setting; Qt::Ch
我已经创建了一个 Guava(一个包含有用的东西的库,几乎可以在任何 Java 项目中使用,包括用于不可变集合、函数式编程、I/O 等等的库)基于 CacheBuilder 的缓存 LoadingC
我正在使用 C# 开发一个 WinForms 应用程序,代码如下: ((CheckBox)page.Controls[check_box_name]).CheckState = CheckState.
我正在寻找 CheckedListBox 的事件,该事件在项目的选中状态更改后触发。 ItemCheckEventHandler 对我不利,因为它会在应用新状态之前触发。 谢谢! 最佳答案 如果您要查
本文整理了Java中org.apache.tomcat.websocket.WsSession.checkState()方法的一些代码示例,展示了WsSession.checkState()的具体用法
谁能告诉我使用 checkboxes 选中属性与 CheckState 属性进行数据绑定(bind)的优缺点? 谢谢。 最佳答案 Checked 只能是真或假(显示复选标记或无),而 CheckSta
我在程序中找不到此问题的解决方案:我使用 JMRTD 库创建并个性化 JCOP 卡,但是在完成后,向服务发送关闭命令,然后再次插入卡,任何尝试执行任何操作都会返回卡已断开连接的信息。我是否缺少重置标志
我需要将 int 和/或 bool 转换为 checkState int ValueCheck; private void gsCheck1_CheckedChanged(object se
我在处理选中的列表框时偶然发现了 SetItemChecked 和 SetItemCheckState。 SetItemChecked 采用列表索引和 True/false 来将列表项设置为选中或取消
我正在尝试设置 Android 项目,但出现以下错误。 Unable to find method 'com.google.common.base.Preconditions.checkState(Z
我将 Apache Beam 与 Cloud Dataflow Runner 一起使用,并在尝试运行管道时出现以下异常: java.lang.NoSuchMethodError: com.google
我正在尝试将 Selenium api 与 Gradle 一起使用。这是我的 build.gradle 依赖部分: dependencies { compile 'com.google.api
我正在尝试将 Selenium api 与 Gradle 结合使用。这是我的 build.gradle 依赖部分: dependencies { compile 'com.google.api
我开发的 Selenium 代码: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; i
我有一个 TestNG 测试,在 Eclipse 中作为 TestNG Suite 运行时可以按预期工作,但通过命令行运行时会失败。我看到无法启动浏览器的问题,但类路径设置工作正常,因为我刚刚打印了h
出现以下错误: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/Str
我是一名优秀的程序员,十分优秀!