matlab 中listbox 增加或删除 选中的项目!

matlab 中listbox 增加或删除 选中的项目!,第1张

这是删除:

n=get(handles.listbox,'value')%获取选中的行号

str=get(handles.listbox,'string')%获取列表中的所有数据

m=size(str1,1)

k=0

for i=1:m

for j=1:size(n,2)

if(i~=n(j))

k=k+1

str1(k,:)=str(i,:)

end

end

end

set(handles.listbox,'string',str1)

添加的话稍微发杂,需要d出一个类似的listbox作为总表,从总表里选,一种做法如下:

再建一个子fig,通过主fig上的add按钮来激发它,在子fig上设置一个listbox和一个pushbutton。将选中的选项添加到主fig的listbox中就行了。两个fig间的互相调用通过句柄的获取和定义来实现,不清楚的话再说。

//添加到listbox2

protected void Button1_Click(object sender, EventArgs e)

{

ListItemCollection Items = new ListItemCollection()

foreach (ListItem item in this.ListBox1.Items)

{

if (item.Selected)

Items.Add(item)

}

for (int i = 0i <Items.Counti++)

{

this.ListBox2.Items.Add(Items[i])

this.ListBox1.Items.Remove(Items[i])

}

this.ListBox2.ClearSelection()

}

//移除listbox2的项

protected void Button2_Click(object sender, EventArgs e)

{

ListItemCollection Items = new ListItemCollection()

foreach (ListItem item in this.ListBox2.Items)

{

if (item.Selected)

Items.Add(item)

}

for (int i = 0i <Items.Counti++)

{

this.ListBox1.Items.Add(Items[i])

this.ListBox2.Items.Remove(Items[i])

}

this.ListBox1.ClearSelection()

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11463470.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存