DdoubleD 315 Posting Shark

I haven't had to use a ListView, but I believe this is how you would do it in your delete click event. Somebody will correct me if I am wrong:

ListView.SelectedListViewItemCollection items = lv.SelectedItems;
            foreach (ListViewItem item in items)
                item.Remove();
DdoubleD 315 Posting Shark

Have you tried Thread.Abort() before trying to exit your app?

DdoubleD 315 Posting Shark

How are you exiting the app?

DdoubleD 315 Posting Shark

Would that work because my understanding of it as im reading it is that it assigns a string a numerical value then compares it to another number. Would that not just tell you which word is greater in length?

No, it works on the sort order of the string: String.CompareTo

DdoubleD 315 Posting Shark

also

if (s.Equals("Hello"))
                bool b = true;
DdoubleD 315 Posting Shark
string x;
x = console.readline();
if (x == "Hello");

it says you can't compare strings.
Hmmm, I thought you could do the "==", but anyway:

private static string CompareStrings(string str1, string str2)
   {

      // compare the values, using the CompareTo method on the first string
      int cmpVal = str1.CompareTo(str2);

      if (cmpVal == 0) // the values are the same
         return "The strings have the same value!";

      else if (cmpVal > 0) // the first value is greater than the second value
         return "The first string is greater than the second string!";

      else // the second string is greater than the first string
         return "The second string is greater than the first string!";
   }
DdoubleD 315 Posting Shark

Hi,

Look I'm new to C# and I have a working knowledge of VB .Net. I would like to learn C# but I'm having a problem. It's probably a basic problem but, for a console program how to I check what someone has typed in so that the console can respond with a Writeline statement?

If they are typing a line:

string s = Console.ReadLine();
            Console.WriteLine(s);
DdoubleD 315 Posting Shark

For lazy's eyes only: get working directory

DdoubleD 315 Posting Shark

// inside PrintDocument or parent...

s/b // inside PrintDocument child class or you could place code in dialog class; whereever the pd_PrintPage event method resides.

Does this make sense?

DdoubleD 315 Posting Shark

For example:

// called when the user selects "Print"
        private void genPrint(object sender, EventArgs e)
        {
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
            printDialog1.Document = pd;
            DialogResult result = printDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                pd.LoadPrintBody();
                pd.Print();
            }
        }

        // inside PrintDocument or parent...
        string[] pBody;
        int lastLinePrinted;
        
        // inside PrintDocument or parent...
        public void LoadPrintBody()
        {
            pBody = rtbReport.Text.Split('\n');
            lastLinePrinted = 0;
        }

        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            //string[] pBody = rtbReport.Text.Split('\n');

            Font printFont = new Font("Courier New", 10);
            float maxLines = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
            float top = ev.MarginBounds.Top;
            float left = ev.MarginBounds.Left;

            // began where left off
            int i = lastLinePrinted + 1;

            for (; i < pBody.Length && i < maxLines; i++)
            {
                float yPos = top + (i * printFont.GetHeight(ev.Graphics));
                ev.Graphics.DrawString(pBody[i], printFont, Brushes.Black, left, yPos);
            }
            if (i < pBody.Length)
            {
                lastLinePrinted = i - 1;
                ev.HasMorePages = true;
            }
            else
                ev.HasMorePages = false;
        }
DdoubleD 315 Posting Shark

You are right about the check on maxLines (I had it backwards).

Can you assign body[] outside of pd_PrintPage? Then retain the lastline printed for each call to pd_PrintPage and pick up where it left off when you make the next call (triggered by ev.HasMorePages)?

DdoubleD 315 Posting Shark

Yea, I've seen what you describe and I don't know how to help you. Maybe someone will see this more descriptive information and have a trick they can share.

DdoubleD 315 Posting Shark

FYI: I also browsed "result" from GetResponseStream, and did not see any reference to megavideo that looked like a URL for it.

DdoubleD 315 Posting Shark

When I view that page, I see the text you said was in french, and their is no link. Can you translate to me this text, and do you see an actual link to a URL when you browse the page? I hope there are not bad words in here.

Pour ceux qui ont déjà pris un compte premium chez MegaVideo, SVP arrêtez de m'écrire à ce propos car ce site est indépendant du site MegaVideo.
Si vous avez des problèmes : Logez-vous avec votre compte premium sur le site MegaVideo puis utilisez le lien [[B]Voir cette vidéo sur MegaVideo[/B]] en bas du lecteur MegaVideo de notre site.
On n'encourage pas nos visiteurs à prendre un compte premium MegaVideo/MegaUpload pour la simple raison que les vidéos de cette plateforme sont supprimées fréquemment.

DdoubleD 315 Posting Shark

Thanks for your reply but I don't use webBrowser control.
I just want to retrieve the URL of the megavideo link in a c# string variable.
When I go to this page with firefox (or ie) I can see that it is http://www.megavideo.com/?v=QJANIB2O

But in the HTML code, this seems to be hiden.

How are you opening the webpage to search for the URL if not in a WebBrowser control? I don't know how to help you if I don't know what you are doing.

DdoubleD 315 Posting Shark

its giving following errors:
1)Operator '<' cannot be applied to operands of type 'int' and 'object'

2)'string' does not contain a definition for 'subString'

1) You are comparing your iterator "s" to the wrong object--you left out the "Length" property in your comparison.

2) spelling error? subString s/b Substring... so it can't find the definition

I could have provided you the code, but don't you think you need to learn why you are getting the errors and try to fix them yourself?

DdoubleD 315 Posting Shark

You are doing it again!
>> But this code is giving error
What error?
Where (what line) did it occur?
And please post your code between CODE tags.

LOL, you read my mind.

DdoubleD 315 Posting Shark

I looked at the webpage and wrote the following snippet to help you find your "iFrame" tag and "MegaVideo" name--it is not tested! It assumes you will have already loaded/navigated to the page in your webBrowser control. Anyway, I hope this helps:

HtmlDocument doc = webBrowser.Document;
                if (doc == null)
                    return null;

                // Get collection of all tags on page with given name
                HtmlElementCollection collect = doc.GetElementsByTagName("iFrame");

                // Loop through each element and find attribute you want
                foreach (HtmlElement element in collect)
                {
                    // if looking for "name" attribute
                    if (element.GetAttribute("name").ToLower() == "megavideo")
                    {
                        value = element.GetAttribute("src"); // "megavideo.php?id=70188"
                        break;
                    }
                }
DdoubleD 315 Posting Shark

Can anyone tell me how can I link
"save as" , "save" , "print", "print preview" buttons to the listbox...

Here is what a menu item's click event wiring looks like. Usually, this is done by the designer, or you can put the code in your form's constructor:

this.mnuFileSave.Click += new System.EventHandler(this.mnuFileSave_Click);

and, you would create an event handler that looks like:

private void mnuFileSave_Click(object sender, EventArgs e)
        {
            // save my listbox items code here
        }

The code is the same for wiring a button's click event. Hope that helps.

DdoubleD 315 Posting Shark

still the problem is there =(

Repost your code changes (complete code) so it can be examined with the changes.

DdoubleD 315 Posting Shark

Can you redraw the panel to cover up the broken lines, before you draw your new border?

DdoubleD 315 Posting Shark

It sounds like you have a web service configuration issue. If you think that might be it, try google'ing your error with added keywords "config" and "Unrestricted".

DdoubleD 315 Posting Shark
FileStream fStream = newFileStream (strPath,FileMode.Append);
fStream.Close();
StreamWriter sWriter = newStreamWriter(strPath);
sWriter.Write(strBuilder);
sWriter.Close();
FileStream fStream = newFileStream (strPath,FileMode.Append);
//fStream.Close();
//StreamWriter sWriter = newStreamWriter(strPath);
StreamWriter = new StreamWriter(fStream);
sWriter.Write(strBuilder);
sWriter.Flush();
sWriter.Close();

The changes should fix your append at least. Not sure if you are even getting it to compile though.

DdoubleD 315 Posting Shark

Try Google'ing: Search Results

DdoubleD 315 Posting Shark

This error message is not very informative, I wish I had a better description of the message.

I guess this is one of those generic catch-all error messages. After some browsing, I've noticed that other applications have somehow hooked into more detailed information related to this error. Does the database or event logs hold details to these error events?

Anyway, wish I could help you more but I don't know your DB, Tables, etc., and there are too many possibilities of what is actually generating this error. Good luck.

DdoubleD 315 Posting Shark

Also, anything other than 0x00000000 in the boolean address would probably be translated true, though I haven't tested that.

DdoubleD 315 Posting Shark

Trick question? In the active code lines, you are overwriting the first byte of your char "theChar", which is two bytes (Unicode) in length, when you assign to your bool "theBool", which is one byte in length; because you have aligned both fields on the first byte ([FieldOffset(0)]) in your structure.

And they said you couldn't do unions in C#. Just don't expect any language support for bitwise manipulation.:icon_smile:

DdoubleD 315 Posting Shark

The libraries (IBMDADB2, DLL's, etc) being access for you database from these calls might be out of sync. Which line (DB call) is throwing the error?

Maybe the OLE DB Provider (IBMDADB2) is not properly registered? You might contact IBM support for this driver and see what they have to say about your error.

DdoubleD 315 Posting Shark

It looks to me like your: string[] pBody = rtbReport.Text.Split('\n') ;
assignment inside of the print page won't work. Don't you need to check for maxlines, return, then reassign pBody where you left off, then allow the print page event to continue?

If you made that adjustment, then this seems logical:

int i = 0;
            for (; i < pBody.Length && i < maxLines; i++) // for each line?
            { 
                float yPos = top + (i * printFont.GetHeight(ev.Graphics));// calc start line
                ev.Graphics.DrawString(pBody[i], printFont, Brushes.Black, left, yPos); // print line
            }
            if (i >= maxLines)
                ev.HasMorePages = false;
            else
                ex.HasMorePages = true;
DdoubleD 315 Posting Shark

It looks to me like your: string[] pBody = rtbReport.Text.Split('\n') ;
assignment inside of the print page won't work. Don't you need to check for maxlines, return, then reassign pBody where you left off, then allow the print page event to continue?

DdoubleD 315 Posting Shark

Is your website using IIS Setting--Anonymous Access/Authentication?
If so, try disabling and turn on Integrated Windows Authentication, then retry your call to: System.Web.HttpContext.Current.User.Identity.Name

DdoubleD 315 Posting Shark

As an alternative to including the Flash player with your install, consider checking for the currently installed version against your system requirements within your application and give them an install dialog (or MessageBox) to launch and get the latest Flash version.

DdoubleD 315 Posting Shark

If you are packaging the Flash player install (already downloaded) with your disk or drive, all you need to do is check to see if they already have it installed, and then launch the program from your installer if they do not.

I assume you expect and know how to check for current installation, minimum version requirement, etc.--before and after installation to detect and verify correct results.

DdoubleD 315 Posting Shark

How about GetCredential?

Uri uri = new Uri("http://mysite.com/");
            ICredentials credentials = CredentialCache.DefaultCredentials;
            NetworkCredential credential = credentials.GetCredential(uri, "Basic");

            string user = credential.UserName;
DdoubleD 315 Posting Shark

For security and other reasons, the browser's download dialog does not give you their local path information. You need to create a custom download dialog for your server's app. that allows the user to directly input the path you want to pass to your new process.

Is it possible for you to launch the new process with a default or blank path and that the process's saveas dialog can handle the details without you needing to actually know the path in your app?

DdoubleD 315 Posting Shark

Is this a web server app and your trying to obtain the username of the logged in user currently accessing the form?

DdoubleD 315 Posting Shark

Not sure which machines user you are trying to obtain, but have you tried:

System.Security.Principal.WindowsIdentity.GetCurrent();
DdoubleD 315 Posting Shark

Also, check out this other related article from MSDN.

DdoubleD 315 Posting Shark

"this"? That's not very descriptive. If it's not the answer or porn I'm going to be upset

Check out this related article.

DdoubleD 315 Posting Shark

Check this

DdoubleD 315 Posting Shark

OK. Instead of initializing "date" outside the loop, restore it inside the loop, but use the Convert.ToDateTime. This is the value from each record we want to compare to to see if it is a min or max value.

Instead of initializing Start and EndDate inside the loop, move those outside the loop (where you have "date" currently): set your StartDate to a very high value; and your EndDate to a very low value.

This should fix it--let me know.

ddanbe commented: Good explanation. +8
DdoubleD 315 Posting Shark

Can you give that to me in c#

Give it a shot yourself in your loop. Then I will help you with questions. Be sure to post your new code.

DdoubleD 315 Posting Shark

Check this

DdoubleD 315 Posting Shark

If your date strings are formatted correctly for string comparisons, you can just initialize them and do a comparison for min and max for each row in your loop (pseudocode):

if minDate = "" or minDate > date then
    minDate = date;
if maxDate = "" or maxDate < date then
    maxDate = date;
arelius commented: He was execellent at helping me out and solving the probelm I had. Very reliable as well. +1
DdoubleD 315 Posting Shark

or, copy rows explicitly:

//
        // Summary:
        //     Copies all rows from the supplied System.Data.DataRow array to a destination
        //     table specified by the System.Data.SqlClient.SqlBulkCopy.DestinationTableName
        //     property of the System.Data.SqlClient.SqlBulkCopy object.
        //
        // Parameters:
        //   rows:
        //     An array of System.Data.DataRow objects that will be copied to the destination
        //     table.
        public void WriteToServer(DataRow[] rows);
DdoubleD 315 Posting Shark

I don't see where you are actually copying the rows, but to limit them to only the first four, you set the rowState to indicate it should be copied:

//
        // Summary:
        //     Copies only rows that match the supplied row state in the supplied System.Data.DataTable
        //     to a destination table specified by the System.Data.SqlClient.SqlBulkCopy.DestinationTableName
        //     property of the System.Data.SqlClient.SqlBulkCopy object.
        //
        // Parameters:
        //   table:
        //     A System.Data.DataTable whose rows will be copied to the destination table.
        //
        //   rowState:
        //     A value from the System.Data.DataRowState enumeration. Only rows matching
        //     the row state are copied to the destination.
        public void WriteToServer(DataTable table, DataRowState rowState);

If you want to limit it to only rows without NULL values, I suppose you could set that up in the rowState before calling the WriteToServer method.

DdoubleD 315 Posting Shark

You need to determine whether there are still more pages to print and set HasMorePages = true. Following EXAMPLE is from MSDN:

// The PrintPage event is raised for each page to be printed.
   private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
   {
      float linesPerPage = 0;
      float yPos = 0;
      int count = 0;
      float leftMargin = ev.MarginBounds.Left;
      float topMargin = ev.MarginBounds.Top;
      string line = null;

      // Calculate the number of lines per page.
      linesPerPage = ev.MarginBounds.Height / 
         printFont.GetHeight(ev.Graphics);

      // Print each line of the file.
      while(count < linesPerPage && 
         ((line=streamToPrint.ReadLine()) != null)) 
      {
         yPos = topMargin + (count * 
            printFont.GetHeight(ev.Graphics));
         ev.Graphics.DrawString(line, printFont, Brushes.Black, 
            leftMargin, yPos, new StringFormat());
         count++;
      }

      // If more lines exist, print another page.
      if(line != null)
         ev.HasMorePages = true;
      else
         ev.HasMorePages = false;
   }
DdoubleD 315 Posting Shark

Check out these ListView methods:

public ListView.SelectedListViewItemCollection SelectedItems { get; }
//or
        public ListView.SelectedIndexCollection SelectedIndices { get; }

//with
        public bool ListViewItem.Checked { get; set; }
DdoubleD 315 Posting Shark

Your welcome. Please mark resolved.

DdoubleD 315 Posting Shark

You need to Flush() and Close() your file after you are done writing to it.