Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
QuestionCrystal Report, Generate same report , multiple times with different parameters as one pdf Pin
beker_usa5-Jul-17 8:27
beker_usa5-Jul-17 8:27 
QuestionText file search, combobox and Datagridview C# Help Pin
Member 132944085-Jul-17 2:15
Member 132944085-Jul-17 2:15 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier5-Jul-17 2:30
mveRalf Meier5-Jul-17 2:30 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 132944085-Jul-17 3:03
Member 132944085-Jul-17 3:03 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier5-Jul-17 7:23
mveRalf Meier5-Jul-17 7:23 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440813-Jul-17 0:00
Member 1329440813-Jul-17 0:00 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier13-Jul-17 0:24
mveRalf Meier13-Jul-17 0:24 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440813-Jul-17 21:35
Member 1329440813-Jul-17 21:35 
I have taken your advise to heart and have managed some breakthrough, but now do really not know what to do next.

My code to read the txt file is as follows:


C#
String Fname = openFileDialog2.FileName;
            string[] raw_text = System.IO.File.ReadAllLines(Fname);
            var lines = new List<string>();
            foreach (var line in File.ReadLines(Fname))

            {
                
                listBox1.Items.Add(line);
            }


I return the lines to a hidden listbox as I do not know how to return it to a datatable.

I then find the dates in the txt file and return it to the combobox as follows:

C#
List<DateTime> logDates = new List<DateTime>();
            string dets;

            //Define regex string for date
            string pattern = @"(?<logDate>(\d){2}/(\d){2}/(\d){2})";
            Regex reg = new Regex(pattern);

            
            //read log content
            string logContent = File.ReadAllText(Fname);

            //run regex
            MatchCollection matches = reg.Matches(logContent);


            //iterate over matches
            foreach (Match m in matches)
            {
                DateTime logTime = DateTime.Parse(m.Groups["logDate"].Value);
                logDates.Add(logTime);
                DatecomboBox.Items.Add(logTime);
                object[] distinctItems = (from object o in DatecomboBox.Items select o).Distinct().ToArray();
                DatecomboBox.Items.Clear();
                DatecomboBox.Items.AddRange(distinctItems);
            }


I really appreciate that you do not write the code for me as I am enjoying learning this.
BUT, am I now going in the right direction?
How do I now combine the amount of dets with the dates in the combobox?
More importantly, how do I only show the information between the combobox selected date and the next date in the listbox?

I strongly believe that if I get someone to explain how regex works or how to search the txt file for the information I need and extract the information I can work on and try to figure out the rest myself.

As for the rules:
1. Read the txt file into lines - DONE
2. Find all distinct dates in the txt file - DONE (Still need to use time as well as dates could be same)
3. Show only information for the selected date and time in the listbox - NOT DONE
4. Find the amount of dets in the listbox usually in this format: 1 PU, 00234 DETS where 1 could be 2 or 3 and 00234 could be from 00001 to 04500 and show in second combobox - NOT DONE
5. Extract the detonator information from the list box for the amount of dets selected into a datagridview. - CAN BE DONE - Extract to Datatable using parser and then to Datagridview.


Help please.
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier13-Jul-17 21:52
mveRalf Meier13-Jul-17 21:52 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440813-Jul-17 22:20
Member 1329440813-Jul-17 22:20 
AnswerRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier13-Jul-17 22:39
mveRalf Meier13-Jul-17 22:39 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Member 1329440813-Jul-17 22:57
Member 1329440813-Jul-17 22:57 
GeneralRe: Text file search, combobox and Datagridview C# Help Pin
Ralf Meier14-Jul-17 1:59
mveRalf Meier14-Jul-17 1:59 
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 
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 

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.