C # Read text and display data in the Dev control -- & amp; lt; Continue & amp; gt;

Source: Internet
Author: User

Previous Article: html "> http://www.bkjia.com/kf/201104/88559.html

Now, I have solved two of my own problems and made some minor changes.

This is the improved running effect:

First, read and display the data after the third row.

Simply, a counter count is defined. The while LOOP reads the text first, and when count is 3, the actually reads what we need.

Int count = 0;
While (strLine! = Null)
{
StrLine = sr. ReadLine ();
Count ++;
If (count = 3)
{
While (strLine! = Null)
{
String [] strArry = strLine. Split ();
DataRow dr = dt. NewRow ();
For (int I = 0; I <= strArry. Length-1; I ++)
{
Dr [I] = strArry [I];
}
Dt. Rows. Add (dr );
StrLine = sr. ReadLine ();
}
Break;
}

Second, the data in the second row is read and used as the column name. This cannot be done. At least I don't know how to do it now. As we have already solved the problems we need, we should not think about it any more and there should be no solutions.

In the running effect, there is a Button for opening the file and a Textbox (used to display the file path ).

This is the basic code for opening a file:

Private void OpenFile ()
{
OpenFileDialog openFile = new OpenFileDialog ();
OpenFile. Title = "open ";
OpenFile. FileName = ""; // file name
OpenFile. InitialDirectory = Environment. GetFolderPath (Environment. SpecialFolder. MyComputer); // enable my computer by default
OpenFile. Filter = "text file (*. txt) | *. txt"; // file type
OpenFile. ValidateNames = true ;//
OpenFile. CheckFileExists = true ;//
OpenFile. CheckPathExists = true ;//
If (openFile. ShowDialog () = DialogResult. OK)
{
// DisplayData (openFile. FileName );
TxtFilePath. Text = openFile. FileName;
}

}

These code for opening files may be more comprehensive online.

The changed source code is not posted, and it is very simple.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.