|
Say if you make a program that alows the user to "save a phone number, or Save a file". How do you save then load the file in the program? And create a directory and access it for the saved items?
I just got into c# when the summer started. So Thanks.
WartHog
|
|
|
|
|
There is no standard way - this is what programs do. You must decide the saving and loading routines.
If you want to write a text file, you can use a TextWriter derivative, like StreamWriter or simply use File.CreateText . When you read it, use a TextReader or simply File.ReadText (which returns a TextReader , an abstract class for other classes like StreamReader .
If you want to write binary files, you can use FileStream to both read and write.
If you want to store these attributes (like the phone number) in an object and serialize that to XML (a text format), then use XmlSerializer defined in the System.Xml namespace.
There's really a seemingly infinite ways of accomplishing this task and it all depends on what you want to do. This is a basic concept, however. I recommend that you read the .NET Framework SDK - especially the programming topics - and pick up a book or two on developing applications with .NET. If you read the .NET Framework SDK - and you should - the class documentation for those classes I mentioned above even have examples.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
It seems that specific books aren't usually recommended here (always the SDK's) but I lived in the C# Unleashed book (published by Sams) for the first six months of C#. Since then, I always have it handy along with Mastering Visual C# .Net which is published by Sybex. I know, the SDKs are free, but for the clarity, the $40 each was worth it!
Between the two, you will find how to do just about everything you need to do. In your projects, you will hit very specific advanced things you want to do (like change colors in a grid) which may not be clear. Then you visit the trusty The Code Project and pull up one of the many examples.
Good luck.
|
|
|
|
|
Thanks I will keep it in mind-its sounds really useful.
-WartHog
|
|
|
|
|
As a user keys text into a combobox I am adding or removing the contents of the list and reloading as needed. The problem is that the cursor jumps to the first character.
How can I stop this from happening or reset the cursor? Is there a better way to do this?
Thanks
|
|
|
|
|
Set ComboBox.SelectionStart to ComboBox.Text.Length to position the cursor after the text in a drop-down ComboBox (as opposed to a drop-down list).
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
In ADO.NET i want to get the row currently displayed in the windows form.The GetRow procedure , which is not intrinsic to .NET Framework , is contained in the Utility Functions region of the code ,do this work.
Anyone know how i can active/use GetRow() procedure ?
|
|
|
|
|
It looks like you need to study a C# programming manual a bit more while improving your English. (you are really living here in the US ???)
A form contains nothing but controls. It does not display anything but controls. So you have some type of control on your form which is displaying data....and some part of that data is related to a row in the database.
You do not mention what kind of database so let's start with an assumption that it is SQL Server. You need an SQLDataReader to read the data, you need to know SQL to format your dynamic request or a stored procedure.
How to execute each is dependant upon which way you get your data. A stored procedure requires you specify this in your connection and you then set the parameter name/value pairs. A dynamic sql requires you construct the SELECT statement.
So if you have a listbox, and a row is clicked which contains a key into your database, then you would do this:
1) Handle the click event and figure out the row selected.
2) Get the value and build the select based on the value in the listbox.
3) construct your reader and issue the Select.
I know of not language (not even VB) which has a GetRow() and you magically get a "row" from a database.
So as you can see....the answer to your still-unclear-question differs based on what control is on the form, what data is in that control, how it relates to the actual database, what database you are accessing, and finally which datareader you need. It requires Forms knowledge, SQL knowledge, database knowledge, C# knowledge. And if you think that GetRow() actually exists, then it shows that you have none of that knowledge.
This signature left intentionally blank
|
|
|
|
|
There is no public GetRow() mthod in any class in the .NET BCL, or ADO.NET, or the old ADO classes.
sasan56 wrote:
i want to get the row currently displayed in the windows form
A Web Form or a Windows Form can display MANY rows. It all depends on what control your using to display them. And what "Utility Functions" are you referring to? Who wrote the library your using?
Once again, you have to be MUCH more specific about your problem, the controls your using, and what you want to accomplish.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There is a way, actually.
When you data-bind a record to a form or other control, you can get the current row from Control.BindingContext . It's important that you read the documentation for that property in the .NT Framework SDK documentation. Using a different binding context to retrieve a BindingManageBase from what you bound to the control in the first place will not work; you must bind to the exact same data source and, optionally, data member.
So, you're obviously binding to a DataSet or DataTable (note: it's far better to bind to a DataSet and set the DataMember of a control (if available) to the name of the table - it opens up more options).
So, lets say you bound your controls to a DataTable (since some don't have a DataMember default):
CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataTable, null];
if (cm != null)
{
DataRowView rowView = (DataRowView)cm.Current;
if (rowView != null) return rowView.Row;
} Again, be sure to read about the BindingContext property and follow the related links. There's quite a bit of information about data-binding and binding contexts in the .NET Framework SDK documentation.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I am trying to use a Com object inside of code only I don't like referencing dlls or ocx's. Using AxImp.exe /source I was able to get the source code for the wrapper of C:\WINNT\system32\macromed\Flash\Flash.ocx file. When I add the source file to my project I get a namespace error
AxShockwaveFlashObjects.cs(21): The type or namespace name 'ShockwaveFlashObjects' could not be found (are you missing a using directive or an assembly reference?)
Could someone try this and see if they get the same error.
Also is there anyway to type in the code for a .Net control that I have in a separate class file and have the VS.NET IDE be able to manipulate it like a ToolBox control. I could have swore I have done that before.
Thanks,
Cyber
|
|
|
|
|
tlbimp.exe and aximp.exe do the same thing as referncing ActiveX controls in the Toolbox and as references from Add Reference - they both generate interop libraries (RCW's). That is the recommended practice.
Even if you add AxShockwaveFlashObjects.cs to your project, you still need to add the interop library Interop.Flash.dll (or whatever it is called) to your project. aximp.exe creates to interop assemblies - one that contains the definition of any ActiveX controls that derive from AxHost , and one that contains the RCW for the typelib (type library). Both are required.
If you want do it the manual way, you must still reference the latter interop library mentioned above. You're duplicating code, though, if you reuse the ActiveX control in other projects. That's why signing the interop assemblies and using them across your projects is a much better idea - granular control.
If you want the control you've compiled into your assembly to be in the toolbox, then after you've compiled your project custom your toolbox (right-click on the toolbox) and browse to your assembly (it won't show up in the list unless you've added the necessary registry key, and for a project in development that's silly - especially in the target directory; at least copy it to a common path). When you click OK after browsing for it, you can check which components (including controls) you want to add to the toolbox.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Is there a pre-existing class/method in .NET or does anyone know of code that will count the number of unique format items in a string (i.e. how many parameters are required.)
In other words, passing "This is {0} a {1} test {0} string" to this method would return 2. (If I could also verify that the string is well formatted, that would be a big plus.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote:
In other words, passing "This is {0} a {1} test {0} string" to this method would return 2.
Ok, I just threw this together but it does the trick. Try the following:
using System;
using System.Collections;
using System.Text.RegularExpressions;
public class Test
{
private int GetFormatItemCount(string s)
{
ArrayList al = new ArrayList();
Regex r = new Regex("{*[0-9]*}");
Match m = r.Match(s);
while(m.Success)
{
if(!al.Contains(m.Value))
al.Add(m.Value);
m = m.NextMatch();
}
return al.Count;
}
[STAThread]
static void Main()
{
Test t = new Test();
string arg = "This {0} is a {1} and {2} and {0} for good measure.";
int count = t.GetFormatItemCount(arg);
Console.WriteLine(count + " items in string.");
Console.Read();
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
I was thinking of this approach, but hoped something was built in that I was missing. This will do for now.
(Note: this fails if the string has double braces like: "This {{0}}")
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote:
(Note: this fails if the string has double braces like: "This {{0}}")
Why are you looking for something like this? I spent 3 minutes on it, there are other areas in which that function could fail as well, if the string were null for example. This should give you a starting place though.
- Nick Parker My Blog | My Articles
|
|
|
|
|
It's for a tool we're prototyping to help third party writers translate strings. As I said, I'd considered the RegEx option, but hoped there was a method built into .Net that could also validate the items as well.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
This forum is to help educate posters about concepts, not provide end-to-end solutions. Sample code is just that - sample code. If you want complete solutions, try browsing or searching the articles, but keep in mind that many of those are just samples as well.
To answer your original question, no there is nothing built into the BCL that does this for you, nor should there be - it's simple pattern matching.
If you want to see how Microsoft does it in StringBuilder.AppendFormat (which String.Format and Console.WriteLine ultimately use), then I suggest you open mscorlib.dll in ildasm.exe from the SDK to view the IL, or download a decompiler (keeping in mind that decompilation is a best-guess solution) like .NET Reflector and view the decompiled code in a supported language of your choice (currently C#, VB.NET, and Delphi are supported).
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
To answer your original question, no there is nothing built into the BCL that does this for you, nor should there be - it's simple pattern matching.
I disagree. Checking whether a formatable string is well formed should be built into the BCL. On more than one occasion, I've had to do something similar for C/C++ projects. I suppose this would be an excuse for an article. (Counting the number of unique format items would be a side effect of this process.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hello everyone,
it is just me with another question:
I am using a TCP socket and asynchronous methods to implement a listening server, which will then re-format and forward these request to a SAP R/3 system.
All this is done in a C# Windows Service with attached SAP .NET connector.
I have everything up and running, BUT I am not sure if it will continue running given that the data is - at least on the listen server side - passed through Encoding.ASCII.GetBytes and Encoding.ASCII.GetString.
I understand that Windows uses UTF8 (ANSI). Is that right?
Now, I BELIEVE that I should use Encoding.UTF8.GetString AFTER receiving and Encoding.ASCII.GetBytes BEFORE sending when communication with my client?
My client is an IBM-Mainframe, complete with terminal-emulation and the dreaded (at least by me) EBDIC. I have been told that the Mainframe auto-magically does an EBDIC-TO-ASCII Conversion before sending to me and ASCII-TO-EBDIC after receiving...
What I am afraid of: I get a package which instructs me to perform a search on the SAP System. I receive in ASCII and do no conversion. The String contains an Umlaut (ä,ö,ü) and I get no result, because SAP uses UTF8...
The same way around, I forward data to the mainframe and since it comes out of my program, its UTF8. The mainframe then is supposed to store this data, checks if its already there and finds its not, so he creates a new table - and it is there, just as ASCII.
If you can sort this out, please feel free to give me some hints.
And dont make em hint* = null
Cheers
Sebs
|
|
|
|
|
Windows uses whatever encoding you tell it to, except that Windows in general (as opposed to Windows NT-based platforms, which include Windows NT 4, Windows 2000, Windows XP, Windows 2003, "Longhorn", and beyond) doesn't support Unicode (that means Windows 95, 98, and Me don't support Unicode without the Microsoft Layer for Unicode linked against your applications). You can still write-out Unicode files from your .NET applications, but no APIs on Windows will understand them.
Encoding.UTF8 is nice because ASCII is still supported (the 7-bit characters) and it's still single-byte unless a trailing byte is necessary (which is described in the upper 128 bits of the byte, so 0x80 to 0xff).
Note that there's really no reason to convert an ASCII stream to UTF8 unless a certain codepage is in use. In such a case, the Encoding.Convert method is handy.
But the encoding you should use is whatever the SAP system supports. If SAP supports UTF8, then use UTF8. A nice way to encapsulate this behavior is to write your NetworkStream in a TextReader and a TextWriter like so:
StreamReader reader = new StreamReader(networkStream, Encoding.UTF8);
StreamWriter writer = new StreamWriter(networkStream, Encoding.UTF8); Now you can read and write strings that will be decoded and encoded (respectively) and send through the NetworkStream as bytes automatically.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I have seen and tried your RowSelectorColumn control from Andy Smith to add Radio button or Check box control as selection column.
But i guess there is some problem with it.
See the problem goes like this. If you can help me out in this it would be great.I want some same functionality as you have provided but as you have extended DATAGRIDCOLUMN, I m extending DATAGRID and as per your example developer has to add
<mbrsc:rowselectorcolumn allowselectall="True" selectionmode="Single">
at design time. But what i m trying out is that if developer selects property either Single or Multiple, My datagrid will automatically add this column on "OnInit" of my Datagrid or CreateChildControl method.
The problem is if i add this on either of the event and if i DONT ADD any further column it works fine but if i try to add ONE MORE COLUMN from designer (from Property Builder) it adds SelectedIndexes="Int32[] Array" as a property and it gives error
<mbrsc:rowselectorcolumn allowselectall="True" selectedindexes="Int32[] Array" selectionmode="Single">
The same this is happening with your control as well.
Now if i remove SelectedIndexes="Int32[] Array" from the HTML and run it gives me TWO RADIO button columns instead of one.
Now to solve this i converted this SelectedIndexes property to method but problem still persist. It still adds two radio columns.
I have tried to check if column adready added using BOOL variable but it doest work as OnInit fires every time and value for BOOL value would be FALSE alway.
Can you pls help me where i doing mistake or how to resolve this problem. I m stuck with problem and its very fustrating that i dot see any logical solution of this.
Thanks a lot in advance.
Bhavesh Amin
|
|
|
|
|
If you have questions or comments about a specific article, then you should ask in the message board at the bottom of that article - that's what the message boards are there for. This forum is for general C# and related .NET questions.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Does anybody know how to set the color of ListView columns???
I need to set the whole columncolor and not only the background color of a
subitem.
Can somebody help me
Thanks
00ason00
|
|
|
|
|