本文介绍了将Combobox(使用ArrayList集合)行添加到richtextbox。一次一行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我创建了一个文本编辑Windows窗体。我的表格上有一个Combobox,我使用和arraylist集合(强制性)为我的Combobox添加了值。现在我想将这些值添加到我的richtextbox中。当我点击组合框中的一行时,
该行应该添加到richtextbox中。有人可以帮忙吗?什么代码需要在"comboBox1_SelectedIndexChanged"中???

Hi, I'm new to C# and I created a text editing Windows Form. I have a Combobox on my form, and I have added values to my Combobox using and arraylist collection (mandatory). Now I want to add those values to my richtextbox. When I click on a line in my combobox, that line should be added to the richtextbox. Can someone help pls? What code needs to be in "comboBox1_SelectedIndexChanged"???

这是我到目前为止所得到的:

       

This is what I've got so far:
       

         private void comboBox1_Click(object sender,EventArgs e)

        {           

            ArrayList presetWords = new ArrayList();

            presetWords.Add(" Outstanding");&
            presetWords.Add(" Super");

            presetWords.Add("做得好");
$
            presetWords.Add(" Good job");

            presetWords.Add("Well well");

            presetWords.Add(" Good going");

            presetWords.Add("几乎在那里");

            presetWords.Add("稍微努力一点");

            presetWords.Add("下次更好运");

            presetWords.Add(" Sorry");

            comboBox1.DataSource = presetWords;

            comboBox1.SelectedIndex = 0;        

        }


        private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)

        {

            

        }

         private void comboBox1_Click(object sender, EventArgs e)
        {           
            ArrayList presetWords = new ArrayList();
            presetWords.Add("Outstanding");
            presetWords.Add("Super");
            presetWords.Add("Well done");
            presetWords.Add("Good job");
            presetWords.Add("Well played");
            presetWords.Add("Good going");
            presetWords.Add("Almost there");
            presetWords.Add("Try a bit harder");
            presetWords.Add("Better luck next time");
            presetWords.Add("Sorry");
            comboBox1.DataSource = presetWords;
            comboBox1.SelectedIndex = 0;        
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

推荐答案

希望这可以帮到你

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsFormsApplication2
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ArrayList presetWords = new ArrayList();
                presetWords.Add("Outstanding");
                presetWords.Add("Super");
                presetWords.Add("Well done");
                presetWords.Add("Good job");
                presetWords.Add("Well played");
                presetWords.Add("Good going");
                presetWords.Add("Almost there");
                presetWords.Add("Try a bit harder");
                presetWords.Add("Better luck next time");
                presetWords.Add("Sorry");
                comboBox1.DataSource = presetWords;
                comboBox1.SelectedIndex = 0;        
            }
            catch (Exception ex) { string errormsg = ex.ToString(); }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                richTextBox1.Text += comboBox1.SelectedItem.ToString() + System.Environment.NewLine;
            }
            catch (Exception ex) { string errormsg = ex.ToString(); }
        }
    }
}







这篇关于将Combobox(使用ArrayList集合)行添加到richtextbox。一次一行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 21:03