我取值的时候会报错procedure TForm1.Button1Click(Sender: TObject); begin ComboBox1.AddItem('afsdf',TObject(10)); end;procedure TForm1.Button2Click(Sender: TObject); begin ComboBox1.Items.Objects[10]; end;先单击Button1 再单点button2
你这个方式我好像也试过不行,也许我不知道怎么用; 我的测试DEMO如下:procedure TForm1.Button2Click(Sender: TObject); var MyList:TStringlist; begin //ComboBox1.Items.Objects[10]; MyList:=TStringList.Create(); MyList.Add('fasf'); MyList.Add('aaa'); MyList.Add('aa'); MyList.Insert(10,'fdsafdsa'); ComboBox1.Items.AddStrings(MyList); MyList.Free; end;我想达到的目标是:前10行中其中有三行才有数据,但是我又在第10行中添加数据,应该怎么样做的问题;且4-9行为NIL
加入空格后,在combobox list中会显示出来啊,我是不想显示;
如果 一定要用 combobox 那么看我的文章 已经解决 很好用 没有内存泄露 http://blog.csdn.net/chinawcs/article/details/6610754还可以用 三方组件解决这个 比如 ehlib中的TDBComboBoxEh while not Ado.Eof do begin cbo.Items.Add(Ado.Fields[1].AsString); cbo.KeyItems.Add(Ado.Fields[0].AsString); Ado.Next; end;
Integer(combobox.items.Objects[index])
另外 RzComboBox 可以这样 procedure TForm1.Button1Click(Sender: TObject); begin RzComboBox1.InsertItemValue(0,'aa','bb'); end;procedure TForm1.Button2Click(Sender: TObject); begin ShowMessage(RzComboBox1.Values.Strings[RzComboBox1.itemindex] ); end; 方法都有三种了 楼主可以结贴了
combobox.InsertItemValue(10, 'AAA', 'AAA');用Ccombobox的InsertItemValue方法,
方法方法参数如下:
InsertItemValue(Index: Integer; const Item, Value: string)
因为ComboBox1为空时或者combobox的intems不超过10时插入会报错
你内容没有这么多当然会出错,你要盖楼,1楼没盖就盖10楼,你说可以吗
如果去序号可以用ComboBox1.ItemIndex+1自带的combobox1只有items,而没有values,只能取items和索引,而不能取自定义的序号
如果要取items和values要使用第三方控件
取的时候用combobox.items.Objects[index]
没有10行的时候,插入到第几行!
add加后面,insert直接插入
抱歉,我搞错了,Raize控件RzComboBox才有这个方法
insert()
else
Add();
1、创建MyList:TStringlist
2、在MyList插入操作
3、 ComboBox.Items.addstrings(Mylist)
begin
ComboBox1.AddItem('afsdf',TObject(10));
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ComboBox1.Items.Objects[10];
end;先单击Button1 再单点button2
我的测试DEMO如下:procedure TForm1.Button2Click(Sender: TObject);
var
MyList:TStringlist;
begin
//ComboBox1.Items.Objects[10];
MyList:=TStringList.Create();
MyList.Add('fasf');
MyList.Add('aaa');
MyList.Add('aa');
MyList.Insert(10,'fdsafdsa');
ComboBox1.Items.AddStrings(MyList);
MyList.Free;
end;我想达到的目标是:前10行中其中有三行才有数据,但是我又在第10行中添加数据,应该怎么样做的问题;且4-9行为NIL
http://blog.csdn.net/chinawcs/article/details/6610754还可以用 三方组件解决这个 比如 ehlib中的TDBComboBoxEh while not Ado.Eof do
begin
cbo.Items.Add(Ado.Fields[1].AsString);
cbo.KeyItems.Add(Ado.Fields[0].AsString);
Ado.Next;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RzComboBox1.InsertItemValue(0,'aa','bb');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(RzComboBox1.Values.Strings[RzComboBox1.itemindex] );
end;
方法都有三种了 楼主可以结贴了
ComboBox1.Items.Insert(9,'AAA');
吧