在表单中显示我的文本文件中的数据 [英] Show data from my text file in a form

查看:72
本文介绍了在表单中显示我的文本文件中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在寻找从我用一个表单创建的文本文件中检索事件并尝试在另一个表单中显示它们。如果我从第二个表单上的日历中选择日期,我需要在组合框中显示事件名称,如果我在组合框中选择事件,则事件的描述和价格和时间等将显示在文本框中。我创建了一个获取和设置值的社区事件类。蚂蚁帮助会很棒,这就是我到目前为止所用的内容

Hi i am looking to retrieve events from a text file i created with one form and trying to display them in another. if I select a date from the calendar on the second form I need the event name to be displayed in a combo box and if i select the event in the combo box the description and the price and time etc of the event appear in the textbox. i have created a community event class that is getting and setting the values. ant help would be great, here is what i have so far

public partial class TicketInformationForm : Form
{ 
  public TicketInformationForm()
  {
     InitializeComponent();
  
  }
  //creating the community events list.
  List<community_event> CommnunityEvents;

  //create the Create Event list method.
  private void CreateEventList()
  {
     CommnunityEvents = new List<community_event>();
     // call the extract Data method.
     ExtractData();

     if (CommnunityEvents.Count &gt; 0)
     {
        //if there are no events for the date selected display the following
        eventComboBox.Text = " -Events- ";
        descriptionTextBox.Text = "Pick an event";
     }
     else
     {
        //if there are no events for the date selected display the following
        eventComboBox.Text = " No Events ";
        descriptionTextBox.Text = "No events today.";
     }
     
  }
  //Assignment 4 Part 2 – Create Method ExtractData
  private void ExtractData()
  {
     CommnunityEvents.Clear();

     // load the data from the file
     List<community_event> tempList = new List<community_event>();
     //string[] fileLines = File.ReadLines(@"C:\Users\IAN\Documents\calendar.txt");

     foreach(string line in File.ReadLines("Calendar.txt"))
     {
        string[] items = line.Split(",".ToCharArray());
           Community_Event newEvent = new Community_Event();
           newEvent.Day = Convert.ToInt32(items[0]);//Converting the Integer to a string.
           newEvent.Time = items[1];
           newEvent.Price = Convert.ToDecimal(items[2]);//Converting the decimal to a string.
           newEvent.Event = items[3];
           newEvent.Description = items[4];
     }
     CommnunityEvents = (from ev in tempList
                                  where ev.Day == 1
                                  select ev).ToList();
  }

  private void dateMonthCalendar_DateChanged(object sender, DateRangeEventArgs e)
  {
     //calling the create event list method to display any events in the eventscombo box.
     CreateEventList();
  }
  
  private void eventComboBox_SelectedIndexChanged(object sender, EventArgs e)
  {
    /*display time, price and desription of any events selected in the combo box and display them
     in the description TextBox*/
     
  }
  private void descriptionTextBox_TextChanged(object sender, EventArgs e)
  {
    
  }
  private void TicketInformationForm_Load(object sender, EventArgs e)
  {
     //calling the create event list to open the form with today's events displayed if any.
     CreateEventList();
  }
}

推荐答案

该代码中没有任何内容显示您使用的是文本文件:如果您是,除非只是将信息从一种形式转移到另一种形式,否则你可能不应该这样做。



如果您要做的是在Form2上选择一个日期,让它影响Form1上显示的内容然后这很简单,但是你究竟是如何做的取决于表单之间的关系。

如果Form1创建Form2的实例:在两个表单之间传输信息,第2部分:Child to Parent [ ^ ]

如果Form2创建Form1的实例: Transferrin g两种表格之间的信息,第1部分:父母对儿童 [ ^ ]

如果Form1和Form2都是由不同的表单(Form3)创建的:在两种表格之间转移信息,第3部分:孩子对孩子 [ ^ ]



如果那不是您所说的,那么您需要澄清您的问题并提供更多细节!
Nothing in that code shows you using a text file: and if you are, you probably shouldn't unless it's for something other than just transferring information from one form to another.

If what you are trying to do is select a date on Form2 and get it to affect what is shown on Form1 then that's pretty easy, but exactly how you do it depends on the relationship between the forms.
If Form1 creates the instance of Form2: Transferring information between two forms, Part 2: Child to Parent[^]
If Form2 creates the instance of Form1: Transferring information between two forms, Part 1: Parent to Child[^]
If both Form1 and Form2 are created by a different form (Form3): Transferring information between two forms, Part 3: Child to Child[^]

If that isn't what you are talking about, then you need to clarify your question and provide more detail!


这篇关于在表单中显示我的文本文件中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆