JerryShaw 46 Posting Pro in Training

Simply place a WebBrowser component on your form then pass it the URL
WebBrowser.Url = TextBox1.text;

JerryShaw 46 Posting Pro in Training

Put a break point on the line
string store = StoreLocator.LocateNearestStore(3, 7);
and press F5, press F11 when on this line, and it will take you into your StoreLocator class.LocationNearest method. From there, press F10 to execute to the next line, or F11 when you want to drill into another method.

JerryShaw 46 Posting Pro in Training

If you used the Min and Max methods from Java, then you can use the System.Math.Max and System.Math.Min methods in C#

Otherwise create a sortable array, get the first and last elements.

Hope that helps,
Jerry

JerryShaw 46 Posting Pro in Training

Hey Shadowwrider,

<code>
ArrayList ar = new ArrayList();
object[] myarray = new object[2];
</code>

ArrayList comes from the System.Collection name space. I find it very useful, and will show you how to use the array or arraylist. Above I declare both for your consideration. Notice that for the standard array, you need to declare it as an array of objects.

In this example we have a very simple struct:
<code>
public struct MyStruct
{
public int t1;
public string s1;
}
</code>

Here is a Simple example using some Console writing:
<code>
ArrayList ar = new ArrayList();
object[] myarray = new object[2];
// First get an instance of the struct
MyStruct thisjoe;
thisjoe.t1 = 1;
thisjoe.s1 = "Hello";
myarray[0] = thisjoe; // Add to the Array
ar.Add(thisjoe); // OR add to the ArrayList

// Do another one
thisjoe.t1 = 2;
thisjoe.s1 = "World";
ar.Add(thisjoe);
myarray[1] = thisjoe;

// How to get a value ? Lets put one into (x)
int x = ((MyStruct)ar[0]).t1;
Console.WriteLine("X={0}", x);

// Lets go through the ArrayList
foreach (MyStruct myjoe in ar)
{
Console.WriteLine("{0}:{1}", myjoe.s1, myjoe.t1);
}

// Lets go through the standard Array
foreach (MyStruct myjoe in myarray)
{
Console.WriteLine("{0}:{1}", myjoe.s1, myjoe.t1);
}
</code>

Hope this Helps,
Jerry

JerryShaw 46 Posting Pro in Training

I think he means parameter not items. Parameters are pased to static methds in the same way that parametes are passed to private , public, etc methods. No special parameter syntax required.

JerryShaw 46 Posting Pro in Training

Is this what you are Looking for ?

using System;
using System.Collections.Generic;
using System.Text;
namespace Blondee2007.cs
{
class Program
{
 
static void Main(string[] args)
{
int sales = 0;
int[] salesArray = new int[10];
while (sales > -1)
{
Console.Write("Enter in the sales for the salesperson (-1 to quit): ");
sales = int.Parse(Console.ReadLine());
if (sales < 0) { continue; }
 
sales = sales + (int)System.Math.Round( 0.09 * sales);
int item = (int)System.Math.Round( (decimal)(sales / 100) );
item = item > 9 ? 9 : item -1;
salesArray[item]++;
} // while
Console.WriteLine("{0}: {1}", "0 -199", salesArray[0]);
Console.WriteLine("{0}: {1}", "200-299", salesArray[1]);
Console.WriteLine("{0}: {1}", "300-399", salesArray[2]);
Console.WriteLine("{0}: {1}", "400-499", salesArray[3]);
Console.WriteLine("{0}: {1}", "500-599", salesArray[4]);
Console.WriteLine("{0}: {1}", "600-699", salesArray[5]);
Console.WriteLine("{0}: {1}", "700-799", salesArray[6]);
Console.WriteLine("{0}: {1}", "800-899", salesArray[7]);
Console.WriteLine("{0}: {1}", "900-999", salesArray[8]);
Console.WriteLine("{0}: {1}", "1000+ ", salesArray[9]);
Console.WriteLine("Press Enter to Quit");
Console.ReadLine();
}
 
}
}
JerryShaw 46 Posting Pro in Training

Examine the InitializeComponent method of your form. You should find the error in that section of code. once cleaned up, you should be able to see and use the designer again... this is a problem that can popup from time to time.

JerryShaw 46 Posting Pro in Training

There are many examples on the Net, but I settled for the version on CodeProject by M.Redth. This is a very simplistic example, but a very good starting point. In my own project, I have enhanced Redth's version to Load and Unload on demand, multiple plugins active at the same time, and a messaging scheme between the Host and one or all active plugins.

Plugins are easy once you get the hang of it.
Cheers, Jerry

http://www.codeproject.com/csharp/pluginsincsharp.asp
http://www.divil.co.uk/net/articles/plugins/plugins.asp

JerryShaw 46 Posting Pro in Training

You mentioned in your original post that you wanted to just post this text data to a listbox.

I took your public string PblReadFile() and changed it to public void PblReadFile() then commented out your return sr.ReadLine(); and it populated the listbox just fine.

Jerry

JerryShaw 46 Posting Pro in Training

Maybe this will shed some light on the subject.

I create an array of object[] that is populated by the current row when using the GetValues method of the SQLDataReader.
I have a set of constants to identify specif columns from the row, however you can use quoted column names instead.
A nice little trick is to save the entire row into the TAG property of my treeview as shown below. while ...Read() is the same thing as while not data.eof.

Have fun,
Jerry

SqlDataReader ogRdr = command.ExecuteReader();
while (ogRdr.Read())
{
Object[] values = new Object[ogRdr.FieldCount];
ogRdr.GetValues(values);
node = treeOperGroup.Nodes.Add((string)ogRdr[COL_OPERGROUPNAME]);
node.Tag = values;
}
JerryShaw 46 Posting Pro in Training
int iMoney = cbCombo.indexof("money");
if (iMoney > -1 )
{  cbCombo.SelectedIndex = iMoney; }
JerryShaw 46 Posting Pro in Training

Solved myself

What I was trying to do was dynamically build a menu item for each
langauge that was added to the application. Each language gets is own directory example: en-US, ar-QA, ...
I needed to make sure I had the resource dll in the directory, then determine its name by using the hosting directory. Pass that name to CulturInfo, and build the menu.
The Code snip below was used to populate a combobox, and a version of this used to create my menu items.

string langcode = "";
string startpath = Application.StartupPath;
foreach (string d in Directory.GetDirectories(@startpath))
{
foreach (string f in Directory.GetFiles(d, "Foo.resources.dll"))
{
 
string[] pathparts = d.Split('\\');
int ipaths = pathparts.GetUpperBound(0);
langcode = pathparts[ipaths];
CultureInfo ci = new CultureInfo(langcode);
cbDefaultLangauge.Items.Add(ci.NativeName+ " ("+ci.EnglishName+"):"+langcode);
}
}
JerryShaw 46 Posting Pro in Training

Answered it myself... learned how to use String.Split("\\")

J

JerryShaw 46 Posting Pro in Training

I have the multiple level path of a filename, and I want to pull out just the immediate parent directory name of this file.

Example: Filename = "c:\temp\extra\test\myfile.txt"
How can I get "test" from this string ?

Thanks in advance
Jerry

JerryShaw 46 Posting Pro in Training

Here is a snip of code from my Login screen. It has the usual Server Name, User name and Password texboxes, and a Login and Cancel button. Mine is hardcoded for a database named SAFEnet. This is using the SQLclient (SQL2005). If you are using another type DBMS, let me know, and I will show you that code.

I use a string to contain the ConnectionString value, then use the replace method to build in the parameters. The Login button calls this code:
There are other ways of handling the string, this just makes it more readable. The bottom line is that you contruct the connection string and pass it to the open procedure of the Connection object.

Note: you will want to wrap the connection in a try..catch

Regards,
Jerry

string ConStr = "Data Source=<SERVER>;Initial Catalog=SAFENET;USER ID=<LOGIN>;Password=<PASSWORD>";
ConStr = ConStr.Replace("<SERVER>", cbServer.Text);
ConStr = ConStr.Replace("<LOGIN>", edOperator.Text);
ConStr = ConStr.Replace("<PASSWORD>", edPassword.Text);
btnLogin.Enabled = false; // Make the Button Disabled;
btnCancelQuit.Enabled = false;
// Check these credentials
SqlConnection conn = new SqlConnection( ConStr );
JerryShaw 46 Posting Pro in Training

Answering myself, so others can see how I did this.

Create the new Menuitem, and populate it from the database fields.
Read the ICON blob field into a memory stream. And get its length. This was the killer, other examples on the net were using other ways to obtain the image length, which resulted in dropping the last couple bytes. Using the stream.Length took care of that.

Create and stream the data into an Icon object.
Then populate the new menuitem image property with the Icon ToBitMap method.

childMenu = new ToolStripMenuItem();
childMenu.Text = (string)rdr["MODULE_NAME"];
// get the image from the Database Column name is "ICON"
byte[] byteData = new byte[0];
byteData = (byte[])rdr["ICON"];
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteData, true);
long n = stream.Length; 
 
System.Drawing.Icon iicon = new System.Drawing.Icon(stream);
childMenu.Image = iicon.ToBitmap();
 
parentMenu.DropDownItems.Add(childMenu);
stream.Close();
JerryShaw 46 Posting Pro in Training

I have an SQL2005 table loaded with ICON (image) BLOBs. I need to dynamically add ToolStripMenuItems to my Windows form including the same row Icon from the database table.

This is a Plugin system where I pull the plugin file (assembly) names from the database according to the operator's rights and place them under a Modules top menu item.

Creating the additional menu items was an easy task, but assigning the Menu image from the IMAGE type column has me frustrated.
The database was populated from ICON files through a Delphi application. So easy to do in Delphi, but I am at a loss in how to accomplish this in C# (VS2005).

Thanks for any Assistance,
Jerry