Click here to Skip to main content
15,892,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440814-Jul-17 2:10
Member 1329440814-Jul-17 2:10 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440814-Jul-17 3:07
Member 1329440814-Jul-17 3:07 
AnswerRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier14-Jul-17 9:41
mveRalf Meier14-Jul-17 9:41 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440817-Jul-17 20:18
Member 1329440817-Jul-17 20:18 
AnswerRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier17-Jul-17 21:33
mveRalf Meier17-Jul-17 21:33 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440828-Jul-17 0:25
Member 1329440828-Jul-17 0:25 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier28-Jul-17 0:26
mveRalf Meier28-Jul-17 0:26 
AnswerRe: Text file search, combobox and Datagridview C# Help Pin
BillWoodruff5-Jul-17 21:44
professionalBillWoodruff5-Jul-17 21:44 
Hi, The Types of your Columns tell me that you want to extract typed objects from your text-data. As Ralf suggests, you are going to have to create a parser to convert text to typed objects, and a typed structure to hold the typed objects. That structure could be a Class, a DataTable, or, a Struct.

But first, consider the source of your data: will that source provide the data in some structured format like XML, JSON, or, even CSV. If the data is in any one of those formats, your work is much simpler.

If it is your code generating the data, then you could focus on simply writing a serializer and de-serializer for your objects/classes. Not hard to do these days.

Also, if there are relatively few data in the text file that you need to parse into objects, and display in the DataGridView, perhaps a "scraping" technique would get what you need, possibly by use of a RegEx.

Suggestion: make an outline of the underlying structure your text file embodies; assuming many instances of the structure in one text file (?): define what markers define the beginning and end of each instance. What fields are always present, which are, optionally, omitted.

Sketch: (ref. : [^])
using System;
using System.IO;
using System.Runtime.Serialization;

namespace MasterBlaster
{
    [DataContract]
    public class Blast
    {
        //>17/05/15-16:40:13:BLAST DRIVER ONic DateTime BlastDriveerOn { set; get; }
        [DataMember]
        public string BlastId { set; get; }

        [DataMember]
        public DateTime BlastTime { set; get; }

        //>PU1053(0005 DETS):
        [DataMember]
        public int BlastInitialDets { set; get; }

        //>1/7B7C35;11/7B70B2;21/7B7058;31/7B83A1;41/7B70D1;
        [DataMember]
        public string[] BlastInitialData { set; get; }
        
        // will not be serialized !
        public string tempInfo;

        public Blast(string id, int idets, params string[] idata)
        {
            BlastId = id;
            BlastInitialDets = idets;
            BlastInitialData = idata;
        }
        
        // keep going ...
        
        // define a serializer
        public static class BlastsSerializer
        {
            static DataContractSerializer dcs = new DataContractSerializer(typeof(Blast[]));

            public static void Serialize(string filepath, Blast[] blasts)
            {
              // will create necessary folder structure if it does not exist
    Directory.CreateDirectory(Path.GetDirectoryName(filepath));
                
                using (var writer = new FileStream(filepath, FileMode.Open, FileAccess.Write))
                {
                    dcs.WriteObject(writer, blasts);
                }
            }

            public static Blast[] DeSerialize(string filepath)
            {
                Blast[] blasts;
                
                using (var reader = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                {
                    blasts = dcs.ReadObject(reader) as Blast[];
                }
 
                return blasts;
            }
        }
    }
}
cheers, Bill
«Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye.» Miss Piggy


modified 6-Jul-17 7:37am.

QuestionIs this madness? The pursuit of single-statement methods Pin
Kevin Li (Li, Ken-un)4-Jul-17 10:13
Kevin Li (Li, Ken-un)4-Jul-17 10:13 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
PIEBALDconsult4-Jul-17 10:21
mvePIEBALDconsult4-Jul-17 10:21 
SuggestionRe: Is this madness? The pursuit of single-statement methods Pin
Richard Deeming4-Jul-17 11:09
mveRichard Deeming4-Jul-17 11:09 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon5-Jul-17 4:44
mvePete O'Hanlon5-Jul-17 4:44 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Marc Clifton4-Jul-17 11:26
mvaMarc Clifton4-Jul-17 11:26 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Bernhard Hiller4-Jul-17 21:31
Bernhard Hiller4-Jul-17 21:31 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
ScottM14-Jul-17 22:49
ScottM14-Jul-17 22:49 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon5-Jul-17 1:08
mvePete O'Hanlon5-Jul-17 1:08 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon5-Jul-17 4:20
mvePete O'Hanlon5-Jul-17 4:20 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Rob Philpott5-Jul-17 23:22
Rob Philpott5-Jul-17 23:22 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Pete O'Hanlon6-Jul-17 0:04
mvePete O'Hanlon6-Jul-17 0:04 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Gerry Schmitz5-Jul-17 5:13
mveGerry Schmitz5-Jul-17 5:13 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
jschell5-Jul-17 6:28
jschell5-Jul-17 6:28 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
Eddy Vluggen5-Jul-17 7:56
professionalEddy Vluggen5-Jul-17 7:56 
AnswerRe: Is this madness? The pursuit of single-statement methods Pin
BillWoodruff6-Jul-17 0:03
professionalBillWoodruff6-Jul-17 0:03 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
Rob Philpott6-Jul-17 0:26
Rob Philpott6-Jul-17 0:26 
GeneralRe: Is this madness? The pursuit of single-statement methods Pin
BillWoodruff6-Jul-17 0:55
professionalBillWoodruff6-Jul-17 0:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.