|
The code below assumes u only need two strings in the array.
If u need a string array, then u can use StringCollection in System.Collections.Specialized
First u need to declare a string[] attribute.
Then put an index in the SetMethod:
public class MyList
{
private string first;
private string second;
private string[] arr = new string[2];
//constructor
public MyList(string first, string second)
{
this.first = first;
this.second = second;
arr[0]=first;
arr[1]=second;
}
public string[] GetArray()
{
return arr;
}
public string[] SetArray(int index, string value)
{
arr[index] = value;
}
}
Hope it helps;)
|
|
|
|
|
|
I want to load data from a file into a RichTextBox Windows control. While loading itself, if the file data is larger than the text box height, I don't want scroll bars to apper, but the text should be autofit in the textbox. (Even if the text in such small size is not readable).
How to Achive this?
Any workarounds please?
Hi ! I'm Av. Happy to be a member of Code Project. Your Views are aprreciated
|
|
|
|
|
Hi, I myself is posting the reply. Try this. I hope it works. Please give suggetions if there are any changes in this code or any other workarounds
// To autofit text in a richtextbox while loading from a file.
Assume that already the file is loaded into the RichTextBox. But before the user can view the textbox,the following should take place.
// Find the Last character of the text in the textbox
string lastchr=txtRich.Text.Substring(txtRich.Text.Length-2,1);
// Find the Last index of it
int lstind=txtRich.Text.LastIndexOf(lastchr);
// Get the Position of the last character ( X and Y Coordinates)
System.Drawing.Point p=txtRich.GetPositionFromCharIndex(lstind);
// Check whether the height of the textbox is less than the y coordinate
// of the last character. If yes, it means Text overflows the textbox.
// So, Reduce the ZoomFactor by 0.01 and check again whether text overflows.
// Repeat this process until text fits in the textbox.
while(txtRich.Height
|
|
|
|
|
hi there,
I have a collection of record in a data table which is populated from a dataset.
I would like to replace some field values in that data table. This replacement is
temporary (I am not going to update it back to database or dataset).
Eg:
EmpID EmpName
1101 My Name
1102 Your Name
What I need to do is, I need to replace all "Emp ID" values to it's corresponding encrypted value.
Answer will be
EmpID EmpName
xabc My Name
ssbc Your Name
Now I am iterating through individual records of my data table and updating with my required value. The iteration took little more time, when I deal with lot of records.
Is there any better way to achieve my result.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Iteration is slow because many lookups are required (especially when you refer to a DataTable or DataRow by its string name, like dataSet1.Tables["Supplies"].Rows[0]["supplier_id"] . Either use enumeration or use a single look-up to get the right DataTable and then use that over and over again. For rows, get the current DataRow once and use that variable over and over for a single iteration (this is always a good idea for anything, anyway*). For rows, however, you'll gain more by using enumeration.
If you need faster speeds than that, then use a database. A DataSet is a poor, poor replacement for a database and is far too often used in lieu of a database.
* Other non-DataSet related bad examples I see are something like this:
foreach (SomeObject so in myObjectCollection)
{
so.Property1.Property1 = "asdf";
so.Property1.Property2 = 1234;
so.Property1.Property3 = someRef;
} Property1 would return an object, so assign that to a local variable and reuse it. That will use far less instructions when you compile and, since it's a reference (if it were a reference, and not a value type) will use no additional memory beyond space for the pointer (32- or 64-bits - hardly measureable)
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I want in my application ie a desktop application to open up an html file from a site specified and get the properties of the form fields on it. Actually the application has to read in the data from the computer in to the appropriate fields in the web page and submit each record one at a time. Is that possible?
|
|
|
|
|
Embed the WebBrowser control (the browsing control that is actually Internet Explorer) in a Form . You can do this by customing your toolbox in VS.NET (where you find all the controls and components) and clicking the COM tab. Find the Microsoft WebBrowser Control and add it. Drag that to a form and two interop assemblies are created - one for the ActiveX control and one for the type library (describes COM types). Then right-click on your Project, select Add References, and find the Microsoft.mshtml.dll assembly that should be installed with VS.NET.
Now in your code cast the AxWebBrowser.Document property to IHTMLDocument2 (be sure to add using Microsoft.mshtml to your source code plus any other namespaces you need, otherwise you'll need to fully-qualify every Type name). From there it's just a matter of walking the Document Object Model (DOM). If you have any experience with DHTML that should be easy. If not, go to the Web Development[^] forum.
There's lots of examples on this site, too. Use the search bar under the logo at the top of the page and try searching for "WebBrowser", for example.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi there, I'm using the FileSystemWatcher class to catch the events when the files I have at a certain directory changes.
In my case, the files in this directory is changed by replacing the files with a new one. The problem I have is that the events of the FileSystemWatcher class triggers even before the copying/replacing process finishes. How can I prevent this from happening?
Thanks,
Rafferty
|
|
|
|
|
You can't change when the events fire. What you can do is try and open the file that your working with as exclusive, FileShare.None. If the file is already open by another process, such as in your case the file is still being written, the open attempt will fail until the copy process closes the file. You must repeatedly try and open the file until it works. When that happens, you'll know that the file copy is done and you can then do whatever your want with it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi! I´ve been trying to use a flash animation in my windows forms application. So far I have managed to show the animation and play it, but I can't find a way to know when the animation finishes. I have looked everywhere but it seems that there is no "OnStop" or "OnFinish" event. Can anyone help me? I would really appreciate it.
Thanks in advance,
Matias
|
|
|
|
|
Your question actually has nothing to do with C# or even .NET. When you include an ActiveX control on your Windows Forms the VS.NET designer actually creates two interoperability assemblies - one for the ActiveX control(s) and one for their type library (typelib). Whatever interfaces, coclasses, enums, etc. that are exposed to automation get exposed to .NET through an RCW, or Runtime Callable Wrapper.
Basically what I'm saying is that what is exposed to managed code is what is defined for the object. In this case, that object is the Flash player. You'd be better off looking in the developer documentation for Flash or asking in a Flash developer forum. You may find some at http://www.macromedia.com/flash[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
No event of the sort you are looking for is raised by the flash player itself, your best bet is to use an fscommand on the final frame to communicate back to the container (your form) when the animation is complete.
|
|
|
|
|
Hello,
i have 2 tables "products" and "suppliers"
the table products and suppliers has the following columns:
Table "products":
product_id, name, price, product_code, supplier (id of the table suppliers column supplier_id)
data:
product_id name price product_code supplier
151432 Summer Tire 56,33 tire00111 3
151476 Winter Tire 31,63 tire00421 4
Table "suppliers"
supplier_id, name
data:
supplier_id name
3 Michelin
4 Bridgestone
Well my problem is how do i solve this problem: Products is the main table when insert a new product from a new supplier, i need first insert the new supplier into the table suppliers after that i need to retrieve the id from the new supplier for the insertion of the new product in the products table. Can somebody give me a example for this?
thanx!
greetings
Sander
|
|
|
|
|
Use DataTable.NewRow on your Suppliers DataTabe to create a new DataRow . Add the right data to the DataRow 's columns like so:
DataRow row = dataSet1.Tables["Suppliers"].NewRow();
row["supplier_id"] = 1;
row["name"] = "Goodyear";
dataSet1.Tables["Suppliers"].Rows.Add(row); You now already have your supplier ID from above, so repeat the process in a similar fashion to add a record to your "Products" DataTable .
Note that the DataSet is not a replacement for a database, however. If this data is data you need to store, you should keep it in a database and use that database to fill a DataSet using a DataAdapter derivative like the SqlDataAdapter (for SQL Server 2000) via DataAdapter.Fill , and update your database using the DataAdapter.Update method, which contains documentation and examples about how to configure a DataAdapter and use the method in the .NET Framework SDK that is installed with VS.NET by default, can be installed stand-alone, and is available online at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
The supplier_id is auto increment so that is a problem how can i solve this problem?
greetings
Sander
|
|
|
|
|
Don't assign it, then. Once you've added the DataRow to dataSet1.Tables["Suppliers"].Rows then access the row["supplier_id"] and you have your auto-generated number.
You really should read the documentation for the ADO.NET classes. A good place to start and get a high-level overview is Accessing Data with ADO.NET[^] in the .NET Framework SDK. This is installed by default with VS.NET and is available online at http://msdn.microsoft.com/library/[^]. It has many examples and discusses all the classes, methods, properties, and events you need to create your solution.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i understand but you need also to update the database right? because maybe the id that is generated (by the database) is not corresponding with the ID that the dataset created, because between the insertion and updating the database a new record was inserted by the another application.
And how does the Adapter look like because you can have only one InsertCommand per OleDbDataAdapter
greetings
Sander
|
|
|
|
|
Yes, but you never mentioned you were updating a database as well.
If you use the designer to set up a DataAdapter derivative in VS.NET (or any design designer) or use a command builder (like SqlCommandBuilder you'll notice that the InsertCommand property is comprised of an INSERT statement followed by a SELECT statement. This is to make sure that any auto-generated fields are selected into the DataTable correctly. This is not necessary for UPDATEs because the fields already existed.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I would like the click/doubleclick events in my code to ony be performed when the LEFT mouse button is clicked once and twice respectively.
The event handler for the double click event, for some reason, requires that the RIGHT mouse button to be clicked AFTER the left mouse button is double clicked. What could possibly be the reason?
Also, the EventArgs parameters for the Click/DoubleClick event handlers do not have (e.KeyState = 1) method attached to it or the (e.Button = MouseButton.Left) like the MouseDown event does.
How could I get the Click and DoubleClick events to respond to the LEFT mouse button only in C# code?
|
|
|
|
|
A double-click is defined as the left (or right, on a left-handed mouse configuration) click times 2 within a certain configurable threshold. In order to handle double-clicks you'll need to implement a Timer and use the Click event to determine if there was a double-click. To fire the event, simply call OnDoubleClick form your base class (the default implementation fires the DoubleClick event).
To only fire the Click event for left clicks, you need to override OnMouseDown and then determine which mouse button is down. Store that as a field. In an override to OnClick , only call base.OnClick if the left mouse button was pressed. A click occurs after a mouse button is pressed and released, so at the time the event is fired no mouse is pressed:
private bool leftMouse;
protected override void OnMouseDown(MouseEventArgs e)
{
leftMouse = e.Button == MouseButtons.Left;
base.OnMouseDown(e);
}
protected override void OnClick(EventArgs e)
{
if (leftMouse)
base.OnClick(e);
} There is no need to check the current mouse configuration for the user since Windows will translate right-clicks to left-clicks if the mouse is re-orientied for left-handed users.
Why doesn't the Click event use the MouseEventHandler (which would dictate that the event pass a MouseEventArgs parameter)? Because it's in response to a mouse press and release as I mentioned above. To store this state data when not necessary is very wasteful. Only in rare cases like yours would it be necessary, so the Framework gives you the means to define such state variables.
If ever you need the position of the mouse or the buttons being pressed anywhere in your code, you can use the static Control.MousePosition and Control.MouseButtons properties. Keep in mind that the Control.MousePosition returns screen coordinate (relative to the upper-right of the screen), so you need to convert them to client-coordinates to typically be of any use. To do this, call the instance method Control.PointToClient on whichever Control requires the client-coordinates in regard to its extents.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a custom control I'm creating that mainly consists of a tab control. When a certain method is called by the main program the control creates a new TabPage and sets it as the active page. The TabPage itself is actually a class that inherits from TabPage rather than the base TabPage and what it is *supposed* to do is automatically create a DataGrid control on the page and bind the grid to a DataTable. The way I've tried to do this is by have a private member in the inherited TabPage class and creating the new DataGrid in the overridden InitLayout method and setting it up there (I set docking to fill). This works fine up to this point. The problem is if I set the databinding in the InitLayout method (I tried OnCreateControl as well) the grid appears and is correctly bound to the correct DataTable but I find a horizontal scroll bar appears halfway up the control that is about half as long as the control itself. If I horizontally resize the containing window or change any of the column widths the scroll bar disappears.
Now the even stranger thing is that if I create a second TabPage it doesn't have this phantom scrollbar, but if I select the first TabPage and create a third page, the scroll bar reappears.
I can avoid the problem by having the main program call another method in the TabPage to bind the data *after* the control has been created, but that rather ruins my encapsulation.
Is this some weird bug?
|
|
|
|
|
Hi
How con I scan a network and list all Computers to a Windows Form??
|
|
|
|
|
Please click "Search comments" at the top of the forum (not the page) and search for something like "list computers". This has been asked and answered more times than I care to count. Knowing how to research problems is an important part of development and the CodeProject site gives you effective tools if you'd just use them.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have been writing a windows app in c# using vs2003. It uses the HansBlomme code for displaying the app in the notification area.
The problem is that when I try to shut down windows (only tested on xp sp2) whilst the app is still running, windows shuts all other applications down but hangs when it gets to mine. Doesnt even bring up a end now dialog, just kind of sits wallowing in its own self-pitty.
Any ideas, anyone else had this problem. Not even sure if it has anything to do with the hansblomme code or not.
Cheers
Mike
|
|
|
|