|
Take a look at the Process.Start method.
To open a URL in the default browser simply type Process.Start("http://www.codeproject.com");
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
hi guys, The way i always connect to SQL through Visual studio is to use a dataset, sqlConnection and SQLDataAdaptor inorder to connect to my database, but imagin i take my Application to another computer and i want to install it there ! now i need to change the database location ! what is the proper way to do so, should i creat a class that keeps the location of my database so i can easily change it or is there any other way ???
Thanx alot guys ! You rock !
|
|
|
|
|
One way to do it is to use a settings file to store the path for the DB then set the ConnectionString accordingly.
private void Form_Load(object sender, System.EventArgs e)
{
string theFile;
string settingsFile = Application.UserAppDataPath + @"\settings.txt";
using (StreamReader reader = new StreamReader(settingsFile) )
theFile = reader.ReadLine();
this.oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + theFile;
try
{
dataAdapter1.Fill(dataSet1, "table");
}
catch
{
MessageBox.Show("Database not found");
}
}
Hope this helps
Mike
Started out with nothing and still have most of it left!
|
|
|
|
|
Hi Mike, thanx man !
where is this setting text file stored ???
|
|
|
|
|
Your welcome
This is from the VS2002 help
=================
If a path does not exist, one is created in the following format:
Base Path\ CompanyName\ ProductName\ ProductVersion
A roaming user works on more than one computer in a network. The user profile for a roaming user is kept on a server on the network and is loaded onto a system when the user logs on.
==================
In my case its located in;
C:\Documents and Settings\Mike Hankey\Application Data\WoodWare\AreaEstimator\1.0.4.0\settings.txt
Glad to be of help. If you have any more questions would be glad to help.
Mike
Started out with nothing and still have most of it left!
|
|
|
|
|
You can put it in the config file for the application. It's an xml file, so you can easily edit it any time.
---
single minded; short sighted; long gone;
|
|
|
|
|
could you plz explain more ! how can i do that ?!
|
|
|
|
|
Search for "app.config read key"[^] and you will find a lot of information.
---
single minded; short sighted; long gone;
|
|
|
|
|
hi
i'm working with DataTables. my DataTable contains the record from a DB table in row and column format. i want to access the record value on a specific location in the datatable by specifying the row and column number, and then retrieving the value on that particular locaion.
how can i do it??
can u plz tell me the syntax
regards
Saira
|
|
|
|
|
Saira Tanwir wrote: my DataTable contains the record from a DB table in row and column format.
What do you mean by "row and column format"?
Saira Tanwir wrote: i want to access the record value on a specific location in the datatable by specifying the row and column number, and then retrieving the value on that particular locaion.
Sorry, I misread what you were saying - I thought you were asking about the table in the database...
In a DataTable you have a collection called Rows. You can access a row by its index
DataRow row = myTable.Rows[rowIndex];
You can then access the column by a column index.
object value = row[columnIndex];
You can't. Databases don't work like that. You can fake it if it is really what you need, but you'll need to add some sort of rownumber column to the table and it will be a real nightmare trying to keep it correctly updated.
A database works on "sets" of data. There is no built in order in a set. You can get the illusion of order by taking into account implementation details of specific databases. For example, in SQL Server you can create a clustered index (usually on the primary key) which will ensure that the data is physically inserted in the order of that index. You can use the ORDER BY clause to sort the rows as they are extracted from the database.
But at the end of it all there is no specific "get me row 42" functionality. SQL Server 2005 has some additional tools to help make faking this easier, but it is still an illusion.
-- modified at 13:11 Sunday 11th February, 2007
|
|
|
|
|
Hi, I am building a text editor, and I would like to undo the last thing done.
so, I used the Undo() method, but found it undoes everything changed, how can I set it so it only changes the LAST thing done?
My code was:
<br />
<br />
rchTextCode.Undo();<br />
<br />
|
|
|
|
|
Err..i haven't realy tested it but how about....rchTextCode.Text.Undo()?
of cource it'll delete everything if u tell it to undo the entire textbox and not the text it in...
|
|
|
|
|
sharpiesharpie wrote: Err..i haven't realy tested it but how about....rchTextCode.Text.Undo()?
This won't work as the String class defines no Undo method.
sharpiesharpie wrote: of cource it'll delete everything if u tell it to undo the entire textbox and not the text it in...
The Undo method only operates on the text of the text box (see the documentation). He meant that it undos all changes applied to the text and not all changes applied to the text box itself.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Actually, there is a rtf.Text.Undo method...
|
|
|
|
|
Mmh, I don't know where you get that.? The RichTextBox.Text property returns a String instance and the String type definitely has no Undo method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Search the articles for "undo". There are some that cover this topic.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I tried and got the Undo() not to undo the whole textbox, but only the latest entry. What I did was I clicked on another object, then clicked on the textbox and added more text. You can probably achieve multi-stepped undo by playing a bit with the TextChanged event from the RichTextBox and changing focus.
Internet - the worlds biggest dictionary
|
|
|
|
|
Hello, I am creating a control that shows an image and a reflection of this one, very similar to which can be seen in the Windows Photo Gallery of Vista Windows: (the miniature to the right)
http://www.winsupersite.com/images/showcase/winvista_rc1_best_12.jpg
The problem is that when attempt to draw an image that is losing opacity, that is to say, to draw degrading that is diminishing the opacity of the reflected image. Since I can do this?
Greetings, sorry for my bad English
|
|
|
|
|
I have a class with a function that returns an ArrayList.
The problem is that I don't want any client that calls the function to be able to add or delete items from the ArrayList. I want to force the client to use my class' other functions to make any modifications (because related data has to be updated).
Unfortunately, speed is an issue, so I can't just copy the ArrayList and send the copy. Also, a copy would allow the client to think he is making a change when it is actually being ignored. I'd prefer him to get a compile error if he calls Add(), for instance.
I can't find any C# syntax that can make a returned value (or a returned parameter) read only. (The C# "readonly" syntax won't let the client replace the ArrayList with another, but WILL let the client change the content of the ArrayList, and so it is insufficient).
Any ideas would be appreciated.
Mark
11 Feb 2007
|
|
|
|
|
Instead of returning the ArrayList itself you could return an enumerator for the ArrayList . Take a look at the ArrayList.GetEnumerator method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
If the only action you want to offer is enumeration, return an enumerator.
If you want to offer a larger subset of ArrayList functionality, create your own
class that:
- either inherits from ArrayList and hides the properties/methods you dont
want to offer,
- or contains an ArrayList and makes public the enumerator plus those extra properties/
methods you want to export.
Luc Pattyn
|
|
|
|
|
Thanks to you both who responded.
I couldn't figure it out without you.
For others interested, here is a minimal solution class which seems to work so far. You may want to add other properties or functions, but this is what I need for now.
I call it a Firm List since, for the user only, the array size is no longer variable but is firm (solidified). The user can read and use each item in the list, but can't make the list contain a different item nor change the number of items in the list.
using System;
using System.Collections;
namespace FreeForAll {
public class FirmList : IEnumerable {
ArrayList foundation;
public FirmList(ArrayList source) {
foundation = source;
}
public IEnumerator GetEnumerator() {
return foundation.GetEnumerator();
}
public bool Contains(object item) {
return foundation.Contains(item);
}
public int Count {
get { return foundation.Count; }
}
}
}
Here is how, within another class, I return a FirmList as property "SomeList". Within this class, I have full accees to the ArrayList itself and all of its abilities.
class A {
ArrayList TheRealList = new ArrayList();
FirmList TheFirmList;
A() {
TheFirmList = new FirmList(TheRealList);
}
...
void SomeFunctionThatAddsMembersToTheArrayList() {...};
...
public FirmList SomeList {
get { return TheFirmList; }
}
}
And, finally, here is how some other code might use it, just like and ArrayList is used:
A aaa = new A();
aaa.SomeFunctionThatAddsMembersToTheArrayList();
FirmList list = A.SomeList;
foreach (object o in list) {
...
}
WriteLine("{0}", list.Count);
if (list.Contains(...)) {...
Hope this helps someone else.
Mark
|
|
|
|
|
In C# you can't mark reference types as readonly.
However you can Encapsulate ArrayList inside a class and provide restricted access to it through methods, properties. You mentioned that speed is an issue otherwise you could have simply returned a clone to it.
|
|
|
|
|
Hi,
I have created a little button on the form called "Close", and when a user clicks it, it displays a messagebox saying "Do you really want to quit?" with an Ok and a Cancel. Then if they click Ok it does : this.Close(); and if not it doesn't do anything.
Now, I want to be able to get data from the X (Close button) on the form to display the same text box or disable the X (Close button) so users have to use the close button that I have created.
Any way of doing this?
Thanks.
|
|
|
|
|
Put all code that show the message box and eventually cancels the closing operation into the event handler for the FormClosing event and inside the button Click event handler simply call the Close method of your form.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|