Mike Askew 131 Veteran Poster Featured Poster

Let me see if I can find some old code I've written..

Mike Askew 131 Veteran Poster Featured Poster

In my experience with listboxes (they use the same fields)

You bind the datatable as the datasource of the combobox, then give the column names for the displaymember and valuemember as required.

Mike Askew 131 Veteran Poster Featured Poster

The DisplayMember and ValueMember settings of the combo-box allow you to make the display value different to the selected one.

Mike Askew 131 Veteran Poster Featured Poster

Can we see said XML file and higlight what causes the issues?

Mike Askew 131 Veteran Poster Featured Poster

Could you not base the progress bar off how many files have been copied?

Max value = total file number
progress value = amount copied?

Mike Askew 131 Veteran Poster Featured Poster

Yup exactly like the are you sure buttons, it forces a response.

try googling "custom modal forms c#"

Mike Askew 131 Veteran Poster Featured Poster

It could probably exist but I dont see the logic behind the three buttons as there is no way apart from using a modal popup to force someone to click x or y button before proceeding. Hence the point that the button is modal.

Because with your method they can click the doStuff button without clicking either other one. The doStuff button can then not force the clicking of either of the other buttons, it is still down to the users choice unless you lock them out using a modal form.

Feel free to correct me if im wrong Deceptikon.

Mike Askew 131 Veteran Poster Featured Poster

The adaption to Deceptikon's response here would be to make a custom form that looks like a message box proving two buttons, 1 and 10, and then use .ShowDialog() on the customer form to display it modally, therefore forcing a response to the form before continuing.

You could then assign the form returning a yes reponse to the 1 button and a no to the 10 button creating what you require.

Mike Askew 131 Veteran Poster Featured Poster

You may need to tweak my variable declaration to get the length right, but you were overwriting the originals passed in as well as returning them to the new array as output.

public string[] HandleString(string[] str)
        {
            string[] TheResults = new string[str.Length];
            for (int a = 0; a <= 51; a++)
            {
                TheResults[a] = str[a];
                TheResults[a] = TheResults[a].Replace("   Hjärter ", "");
                TheResults[a] = TheResults[a].Replace("   Ruter ", "");
                TheResults[a] = TheResults[a].Replace("   Spader ", "");
                TheResults[a] = TheResults[a].Replace("   Klöver ", "");
            }
            return TheResults;
        }
Mike Askew 131 Veteran Poster Featured Poster

If myObject.HandleString(Cards); has a return value, CardsNumber = myObject.HandleString(Cards); will set CardsNumber to be that value.

Cards would be modified if it is a form level variable and the method makes changes to the Cards variable within it.

Can we see the method code and that might help find the change that you dont want.

Mike Askew 131 Veteran Poster Featured Poster

You have two options to convert a string to an integer, convert and tryparse.

string TempString = 0;
int OutInt = Convert.ToInt32(TempString); // This will exception if not viable to convert to integer

string TempString = 0;
bool Success;
int OutInt;
Success = int.TryParse(TempString, out OutInt); // This will return true if the convert was successful and false if it wasn't but will NOT exception and is generally the better practice.
Mike Askew 131 Veteran Poster Featured Poster

Mod, by earning the management teams respect and trust, along with other factors most likely.

Admin, can't say I know.

Mike Askew 131 Veteran Poster Featured Poster
using System.Text;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Cassandra myObject = new Cassandra();
            string a ="söt";
            a = myObject.hejsan(a);
            System.Console.WriteLine(a);
            Console.ReadLine();
        } 
    }
class Cassandra
        {
            public string hejsan(string value)
            {
                value +="Cassnadra";
                return value;
            }
        }
}

Line 10, you need to assign a to be the output of the method, as I have done in the above code.

Mike Askew 131 Veteran Poster Featured Poster

Nono, look at the first line of my code block, that is where the brackets go.

public string[] CreateCards()

Mike Askew 131 Veteran Poster Featured Poster
public string[] CreateCards( string[] Cards)
        {
            Cards = new string[52];
            for (int a = 0; a <= 51; a++)
            {
                if (a <= 12)
                {
                    Cards[a] = "   Hjärter " + (a+1).ToString();
                }
                if (a > 12 && a <= 25)
                {
                    Cards[a] = "   Ruter " + (a-12).ToString();
                }
                if (a > 25 && a <= 38)
                {
                    Cards[a] = "   Spader " + (a-25).ToString();
                }
                if (a > 38)
                {
                    Cards[a] = "   Klöver " + (a-38).ToString();
                }
            }
            return Cards;  //i get wrong here saying i need to return an array and Cards[] wont work
            //because they expect a value
        }

Need to add [] to the return in method declaration to make it an array.

Mike Askew 131 Veteran Poster Featured Poster

Whats the CashAccRef declared as in the database? What type? As I assume its going to be a mismatch between what you are passing and what it expects.

Mike Askew 131 Veteran Poster Featured Poster

Im pretty sure it will be similar to the ListView approach, using a SQL query with a variable added in passing a primary key of some sort.

Mike Askew 131 Veteran Poster Featured Poster

So... I must not be reading the other part of the SQL Correctly. I'm not to sure what
this part means.. ={0} ?? what is this trying to reference?

Right to explain this. The following two lines of code do the same thing.

Console.WriteLine("The cat sat on" + " the " + "mat.");
Console.WriteLine(string.Format("The cat sat on {0} mat.", "the");

Basically the second line allows you to insert the values after the actual text string, so in the above case, the string "the" is added where {0} is. For longer strings with multiple entries it is simply comma-seperated values after the string like so:

Console.WriteLine("The {0} sat on the {1} and the {2} ate it.", "cat", "mat", "dog");

Obviously the strings can be replaced with any sort of variable, in your case the .Tag property.

Basically it keeps strings cleaner that concatenating everything with +'

Mike Askew 131 Veteran Poster Featured Poster

Right im fast running out of ideas at the moment :D

Have you checked the SQL string at run time is correct? Ie. the .tag is correctly being passed into the sql.

Mike Askew 131 Veteran Poster Featured Poster

Its declared but isnt instanciated (I could be completely wrong here, and it wont make a difference) but try: DataTable cashOrderTable = new DataTable(); on line 15.

Mike Askew 131 Veteran Poster Featured Poster

Hmm outside my knowledge on how to get the exact string, my attempts have failed so far.

Mike Askew 131 Veteran Poster Featured Poster

cashOrderTable is not declared as a new datatable prior to use. Im guessing that might be it? Unless that is declared and instanciated elsewhere?

Mike Askew 131 Veteran Poster Featured Poster

And what happens when running this? It should just show a message when you select something new stating the tag and name.

Mike Askew 131 Veteran Poster Featured Poster

Your welcome, mark the post as solved please :)

Mike Askew 131 Veteran Poster Featured Poster

So just the title info?

Sorry the explanation confused me xD

Mike Askew 131 Veteran Poster Featured Poster

It would be the a reference to the column holding the customerID.

and yeah I know the brain fried feeling..

Mike Askew 131 Veteran Poster Featured Poster

Ummm.. listView1.Items[listView1.Items.Count - 1].Tag = x

That line would be added into the current for-each loop.

Mike Askew 131 Veteran Poster Featured Poster

Ok so I achieved a similar effect using the ListView's tag property.

This is how I added some fake data, its an adaption to your code shown in post #1

edit: by which I mean the for-each loop, the table structure is identical to my above post, I continued using all that code to do this :)

foreach (DataRow row in DS.Tables["NameTable"].Rows)
{
    ListViewItem temp = new ListViewItem();
    temp.Text = row.ItemArray[1].ToString();
    temp.Tag = row.ItemArray[0].ToString();
    listView1.Items.Add(temp);
}

This hides the ID in the tag property of the individual item on the listview.

You can then adapt my code in the ListBox post to instead look at the tag property of the selected item to view the ID and carry out the SQL.

Used this line to check the tag worked etc on ListView selected index changed

foreach (ListViewItem item in listView1.SelectedItems)
{
    MessageBox.Show("Tag: " + item.Tag + " | Text: " + item.Text);
}

Hopefully that might work :)

On a seperate note - your welcome Mark :) Good ol' waiting on email replies giving me time to write this

Mike Askew 131 Veteran Poster Featured Poster

Well thats the best blunder I've pulled off on this site... Skimread the question and never re-read it!

Gimme a while and I'll try figure it out :)

Mike Askew 131 Veteran Poster Featured Poster

Ok sorry for this not being actual code but its quicker for me to write to the code in a descriptive process and answer questions than mess around with setting up fake datasets and then try to SQL them (been trying for the last 20 mins and failing).

To bind a listbox to a data source.

Dataset: DS

For example we have a table called CustomerTable with two rows CustomerID and CustomerName, will assume we have already run the SQL to select this information and it is in the dataset DS

And a second called OrderTable with rows OrderID, CustomerIDFK and ItemID which we will be running SQL off.

Our listboxes are List1 and List2.

To setup our first list with the customer names and their ID's as the selected value:

List1.DataSource = DS.Tables["CustomerTable"];
List1.DisplayMember = "CustomerName"; //The column name as a string
List1.ValueMember = "CustomerID";

So now in the SelectedIndexChanged action of the listbox List1 we will run an SQL query to the second table.

string SQLToRun = string.Format("Select * From OrderTable Where CustomerIDFK = {0}", List1.SelectedValue); //The string.Format allows use of {0} and then specifying the value after the end of the string, makes it a bit tidier than cutting off the string at '=' and then concat'ing the .SelectedValue in

This would return all the rows matching the CustomerID selected in List1 (it probably wouldnt as im rusty with SQL but oh well!)

And then following the same steps as with List1 we …

Mike Askew 131 Veteran Poster Featured Poster

Could you not store which image is selected in a Session? and then pull up the correct image on the next page using the session value?

(don't do much ASP.Net work so cant remember if this works)

Mike Askew 131 Veteran Poster Featured Poster

@nmaillet, Didn't know you could leave the second part of the count specifier blank for any amount :)

@nesa24casa - the fix for my solution with your updated requirements using nmaillet's capturing. Also made it so it captures both <tab> and \t for the sake of covering all options :) simply remove |<tab> from the regex if you dont need it covered

string inputString = "nesa\t\tpera<tab><tab><tab><tab>nn\t\t\t\t\t\tkkn";
            string regexMatch = "(\t|<tab>){2,}";
            string regexReplace = ",";
Mike Askew 131 Veteran Poster Featured Poster

That works too :)!

Mike Askew 131 Veteran Poster Featured Poster

I will try to get back to you this afternoon, work is busy.

Else I'll write up an example tomorrow :)

Sorry for the inconvienience.

Mike Askew 131 Veteran Poster Featured Poster

See my response on here: http://www.daniweb.com/software-development/csharp/threads/432707/help-with-linking-ids-to-show-in-listview-below

It is a similar question.

Listboxes have the ability to store different values underlying to what the user sees and utilising this will make the retrieving of data alot easier.

Mike Askew 131 Veteran Poster Featured Poster

Hi Mark,

You would need to set up the first list so that the .SelectedItem in list box (What you can physically see) is as you state above, but the .SelectedValue contains the actual ID value.

Then the SQL can adjust too:
SELECT ID,QTY,Description,Supplier,Date,Cost,Sell from cashOrders INNER JOIN cashCustomers ON cashOrders.cashAccountRef_FKID=cashCustomers.CashAccRef WHERE cashCustomers.CashAccRef = " + listview1.SelectedValue;

Havent tested this so the SQL might not work but thats the jist of it. It basically selects all the required information from the cashOrders table based on the Id linked to the cashCustomers table where we compare that to the passed ID value from the .SelectedValue of the listbox1.

In terms of binding the listbox to get the information working correctly, if I remember rightly, it is done by binding the listbox to the datasource and then specifying which columns are the .DisplayMember (is visually seen) and .DataSource.

That probably isnt explained clearly as its been about a year since I've done such xD

This might help explain it also.

Mike Askew 131 Veteran Poster Featured Poster
        string inputString = "nesa<tab><tab>pera<tab><tab><tab><tab>nn<tab><tab><tab><tab><tab><tab>kkn";
        string regexMatch = "(<tab>){2,20}";
        string regexReplace = "<tab>";
        string outputString;

        outputString = Regex.Replace(inputString, regexMatch, regexReplace);
Mike Askew 131 Veteran Poster Featured Poster

Specifically for <tab>

Match: (<tab>){2,20}
Replace: <tab>

This will match occurances of <tab> between 2 and 20 in a row, can adjust as needed. Works on your provided example though.

Input: nesa<tab><tab>pera<tab><tab><tab><tab>nn<tab><tab><tab><tab><tab><tab>kkn
Output: nesa<tab>pera<tab>nn<tab>kkn

Mike Askew 131 Veteran Poster Featured Poster

Sorry, easy fix, replace the current bottom if statement with:

                    if (countNum != skipNum)
                    {
                        // Use static Path methods to extract only the file name from the path.
                        fileName = System.IO.Path.GetFileName(s);
                        destFile = System.IO.Path.Combine(targetPath, fileName);
                        System.IO.File.Copy(s, destFile, true);
                        skipNextFiles = true;
                    }
Mike Askew 131 Veteran Poster Featured Poster

Code is tweaked and tested. With a skipNum of 2, I got files copied: 1, 2, 5, 6, 9, 10 of 10 files.

static void Main(string[] args)
        {
            string fileName;
            string destFile;
            string sourcePath = @"C:\Users\maskew\Documents\DaniWeb\Source";
            string targetPath = @"C:\Users\maskew\Documents\DaniWeb\Destination";
            // To copy all the files in one directory to another directory.
            string[] files = System.IO.Directory.GetFiles(sourcePath);
            // Copy the files and overwrite destination files if they already exist.
            bool skipNextFiles = false;
            int skipNum = 2; //as per the example, set this however you like.
            int countNum = 0; //used to track how many files copied since last skipped file.
            foreach (string s in files)
            {
                if (skipNextFiles)
                {
                    if (countNum != skipNum)
                    {
                        countNum++;
                        if (countNum == skipNum)
                        {
                            countNum = 0;
                            skipNextFiles = false;
                        }
                    }
                }
                else
                {
                    if (countNum != skipNum)
                    {
                        // Use static Path methods to extract only the file name from the path.
                        fileName = System.IO.Path.GetFileName(s);
                        destFile = System.IO.Path.Combine(targetPath, fileName);
                        System.IO.File.Copy(s, destFile, true);
                        countNum++;
                        if (countNum == skipNum)
                        {
                            countNum = 0;
                            skipNextFiles = true;
                        }
                    }
                }
            }
        }
Mike Askew 131 Veteran Poster Featured Poster

Ah shoot sorry missed that when reading the reqs, gimme a min, going to put this into visual studio and fix it.

Mike Askew 131 Veteran Poster Featured Poster
    static void Main(string[] args)
    {
        string fileName;
        string destFile;
        string sourcePath = @"E:\Source";
        string targetPath = @"E:\Destination";
        // To copy all the files in one directory to another directory.
        string[] files = System.IO.Directory.GetFiles(sourcePath);
        // Copy the files and overwrite destination files if they already exist.
        int skipNum = 1; //as per the example, set this however you like.
        int countNum = 0; //used to track how many files copied since last skipped file.
        foreach (string s in files)
        {
            if (countNum != skipNum)
            {
                // Use static Path methods to extract only the file name from the path.
                fileName = System.IO.Path.GetFileName(s);
                destFile = System.IO.Path.Combine(targetPath, fileName);
                System.IO.File.Copy(s, destFile, true);
                countNum++;
            }
            else
            {
                countNum = 0;
            }
        }
    }

Have written this in the reply without testing but its pretty simple so should work hopefully, lemme know any errors and i'll resolve.

Mike Askew 131 Veteran Poster Featured Poster

Change the value in the dataset it is bound too, and then update the datagrid.

Mike Askew 131 Veteran Poster Featured Poster

Datagrid paging: http://www.codeproject.com/Articles/16303/DataGrid-Paging-C-Windows-Forms

What exactly is the issue with the progress bar? Does it update? Or does it stay blank and update at the end? Please clarify

Mike Askew 131 Veteran Poster Featured Poster

It is worth noting if you are not running a multi-threaded application the load bar will not update normally as the form will 'freeze' until the whole thread has run, ie. bar will jump from 0% to 100%.

Mike Askew 131 Veteran Poster Featured Poster

Ah thats fine then was just double checking, it would still show up when disabled so dont worry about it.

Mike Askew 131 Veteran Poster Featured Poster

It is worth reading the "Read before posting" post next time Q8iEnG.

B – Please Uninstall or Disable any P2P (peer-to-peer) programs on the infected computer before posting in this forum. Rather than write a long piece on the dangers of P2P, I’m just going to say this:
P2P software circumvents common-sense security measures and opens a user’s computer to a world of hurt.
Our regular volunteers' time is valuable and most are not willing to waste it on a machine that is almost certain to be reinfected in short order.
So, please remove or disable all P2P software for the duration of the cleaning process. Failure to do so may result in your thread being ignored.

and when we look through your logs..

"{1D153C11-407C-4823-B602-8C1EACFA2F3A}" = protocol=6 | dir=in | app=c:\program files (x86)\utorrent\utorrent.exe |
"{37F69D7D-74C5-46E5-8A50-8558958E15B2}" = protocol=17 | dir=in | app=c:\program files (x86)\utorrent\utorrent.exe |

That is also most likely the origination of your problem right there :)

Mike Askew 131 Veteran Poster Featured Poster
Mike Askew 131 Veteran Poster Featured Poster

That's also fine, mine was written the way it is as you said the HREF was dynamic and so mine covered all bases.

Don't for get to mark the thread as solved if your issue is fixed.

Mike Askew 131 Veteran Poster Featured Poster

That should do it for you. The output filename is passed in the method call, the folder paths can be changed using the variables.

        static private void ExtractJPEGNames(string OutputFileName) // eg. "PicIDs.txt"
        {
            string sourcePath = @"E:\Source\";
            string targetPath = @"E:\Destination\";
            StreamWriter StrmWtr = new StreamWriter(targetPath + OutputFileName);

            string[] tempArray = Directory.GetFiles(sourcePath);
            List<string> filesInFolder = new List<string>();
            foreach (string fileName in tempArray)
            {
                string tempID = fileName.Substring(fileName.LastIndexOf('\\') + 1, 3);

                if (!filesInFolder.Contains(tempID))
                    filesInFolder.Add(tempID);
            }

            foreach (string fileID in filesInFolder)
            {
                StrmWtr.WriteLine(fileID);
            }

            StrmWtr.Flush();
            StrmWtr.Close();
        }