combobox中如何设置TEXT

shirong 2001-03-03 10:16:00
我将COMBOBOX设置成了只下拉,但是此时无法设置其中的文本显示,请问谁有办法?是不是要发送消息?
...全文
139 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shirong 2001-03-04
  • 打赏
  • 举报
回复
谢谢诸位,java-scu、winsun、qkl三位给出了正确的解决方法,谢谢
我把分给了JAVA-SCU了。另两位各给5分
xzisgood说的跟我的问题不是一回事,不过还是谢谢!
qkl 2001-03-03
  • 打赏
  • 举报
回复
将COMBOBOX设置成了只下拉时,如果设置的Text的字符串在该COMBOBOX.Items中,COMBOBOX会自动显示该文本(这时ItemIndex=该字符串在COMBOBOX.Items中的索引),否则将显示空(这时ItemIndex=-1)
Java_SCU 2001-03-03
  • 打赏
  • 举报
回复
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.ItemIndex:=n;
end;
xzisgood 2001-03-03
  • 打赏
  • 举报
回复
通过程序
ComboBox1.Items.Strings[0]:='FIX';
ComboBox1.Items.Strings[1]:='HELLO';
Wingsun 2001-03-03
  • 打赏
  • 举报
回复
此时好像只能通过设置ItemIndex来设置Text,你可以在Items中找到你要找的Item然后设置ItemIndex就可以了。
public partial class Form1 : Form { public Form1() { InitializeComponent(); } SerialPort port1 = new SerialPort(); string InputData = String.Empty; delegate void SetTextCallback(string text); private void Port_Select() {//获取机器的串口地址 string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { comboBox1.Items.Add(port); } } private void Form1_Load_1(object sender, EventArgs e) { Port_Select(); this.comboBox1.SelectedIndex = 0; this.comboBox2.SelectedIndex = 0; } private void button1_Click(object sender, EventArgs e) { if (button1.Text == "关闭串口") //当要关闭串口的时候 { port1.DiscardOutBuffer(); port1.DiscardInBuffer(); port1.Close(); button1.Text = "打开串口"; label3.Text = "串口当前状况:未打开"; comboBox1.Enabled = true; comboBox2.Enabled = true; } else if (button1.Text == "打开串口") //当要打开串口的时候 { try { port1.PortName = comboBox1.SelectedItem.ToString(); port1.BaudRate = Convert.ToInt32(comboBox2.SelectedItem); port1.DataBits = 8; port1.RtsEnable = true; port1.Open(); port1.DiscardOutBuffer(); port1.DiscardInBuffer(); button1.Text = "关闭串口"; comboBox1.Enabled = false; comboBox2.Enabled = false; label3.Text = "串口:" + comboBox1.SelectedItem.ToString() + " 波特率:" + comboBox2.SelectedItem.ToString() + " 数据位:8 "; } catch { button1.Text = "打开串口"; label3.Text = "串口:" + comboBox1.SelectedItem.ToString() + "打开失败"; MessageBox.Show("该串口无法打开"); } } } 资源部分代码

5,931

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧