|
i had the same problem a few months ago and i also hadn't found a good solution. my workaround was a union including my datatable and an "empty" datarow.
|
|
|
|
|
Funny thing is that MS also suggests this practice:
http://www.windowsforms.net/FAQs/default.aspx?PageID=2&ItemID=722&CategoryID=3&tabindex=3
But again it can't be too hard to make something like DateTimePicker's ShowCheckBox.
|
|
|
|
|
Hi Guys,
Im fairly new to the world of C#.... Im in the process of building a web form that uploads a CSV file to my server from there it will have to read the file and store the output in an Array. Ive read through the countless tutorials on various sites around the place, but im finding this a little tricky. so all i need is a simple class that can read the contents of a CSV and store it in an array. can anyone of you fine c# gurus assist in this relatively simple app ?
cheers
|
|
|
|
|
Hi,
Easy way is this;
using System.IO;
.
.
public string[][] readCSV(string fileName)
{
StreamReader read = new StreamReader(fileName)
string [][] content = new string[100][100];
int row =0;
for(string line = read.ReadLine();line!=null;line=read.readline())
{
content[row][0] = line.Split(',');
row++;
}
return content;
}
Please let me know if it helps
Neo
|
|
|
|
|
string [][] content = new string[100][100]; i was getting an error on this line. invalid rank specifier sorry but i am still only a newbie with c#
|
|
|
|
|
|
How to get icons in GUI
Keshav Kamat
India
|
|
|
|
|
Ok. I got how to add it.
We have to use a tool strip and then add buttons, labels etc accordingly.
However, If i need to change the image of the buttons, for example, if I want a button to display a file icon, I have to change it in the properties.
In that case, I have to choose the image.
Can some one tell me where all the icon files are stored.?
Keshav Kamat
India
|
|
|
|
|
Hi!
i want to use threads in my C# asp.net web application. i m able to use static function in thread but when i use nonstatic function in my thread with the instance of class then it gives no error or exception but thread is not started and no functionlity in done in thread.
Can anybody help me 4 solving this problem. I need pure C# code not Html.
Thanx
|
|
|
|
|
Hmph... when user sends request to server it is serviced in new thread. When that request is finished all resources are released so probably same happens to thread you made and instance of class which method you call.
Surely there are better ways to solve any kind of problem you have... what are you trying to accomplish?
|
|
|
|
|
I want to see an example of threading in HTML
Seriously, though, there shouldn't be a difference between static and instance methods except that thread safety is normally easier to manage in static methods. I've used both techniques any they work great.
Damn, i just realised that you are in ASP.Net. Are static variables shared between instances and instance variables per instance? The code below is for winforms but i guess it's not going to help much.
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
TestingMethod();<br />
}<br />
private void TestingMethod()<br />
{<br />
myObject obj = new myObject();<br />
Thread t = new Thread(new ThreadStart(obj.SlowMethod));<br />
t.Start();<br />
}<br />
}<br />
class myObject<br />
{<br />
public void SlowMethod()<br />
{<br />
Thread.Sleep(10000);<br />
Console.WriteLine("here");<br />
}<br />
}
This code seems to work fine for me.
HTH
Russ
|
|
|
|
|
I've looked up and down for this and came up short. I'm trying to change the scrollbar position of a site loaded into a WebBrowser (2.0) control.
Edit:
And by scrollbar position I mean being able to set the X/Y values. Something along the lines of: (pseudo code)
webBrowser.SetScrollPosition(500, 500);
That would scroll the document 500 pixels to the right as well as 500 pixels down.
|
|
|
|
|
I sort of got it to display how I want it to but it's pretty rigged and still not 100% right.
This is what I used:
webBrowser.Document.GetElementById("Submit").ScrollIntoView(false);
This auto-scrolls it so I'm right by the submit button. Cool. There is a minor problem though. Due to the way the page is displayed it's quite a bit off center horizontally so I'd like to fine tune the X axis.
The "ScrollLeft" and "ScrollTop" properties don't seem to do anything at all. MSDN says it does exactly what I want to do.
The distance, in pixels, between the top edge of the element and the top edge of its content.
Yet, modifying those values does absolutely nothing.
Also it's kind of rigged because I depend on a form field to get the basic view point. Is there any other way?
|
|
|
|
|
Hello,
I am trying to create my own user control that is like a scrolling band of image thumbnails (like a sideways listview).
I've got my base class of thumbnails ("Thumb"), and the collections class ("Thumbs"), and the "ImageView" class more or less assembled and working (I can add thumbs, count etc.) but I can't seem to get the thumbs to actually display in the ImageView class object. Even if the Thumb class is just a coloured picturebox I can't seem to get it to show up in the ImageView class (or anywhere else). I tried providing an override to OnPaint but I must not be doing something correct there.
Any help is *most* appreciated. Thank you.
Andy
|
|
|
|
|
We're going to need more information to help you, Andy. Probably code snippets too.
You may populate some surface with PictureBoxes and assign your images/bitmaps(?) to each; or you can paint your bitmaps directly to the surface -- which will generally be a lighter-weight approach (in terms of resource footprint). There are some good articles on this site which show you how to paint a bitmap to a surface. You might want to use a scrollable surface.
|
|
|
|
|
Thanks for the reply. I tried to keep it brief the first time
(I've changed the class names to avoid confusion w the word Image)
So my basic class is called Cover (as in album cover). For now, it is just a picturebox with a property that allows me to change the background colour.
I then have the collection Covers :
public class Covers : System.Collections.CollectionBase
{
#region Indexer
public Cover this[int index]
{
get
{
if (index < 0 || index > this.List.Count)throw new ArgumentOutOfRangeException();
return (Cover)this.List[index];
}
}
#endregion
#region Adding methods
public Covers Add(Color _colour)
{
Cover newCover = new Cover();
newCover.BackColor = _colour;
this.List.Add(newCover );
return this;
}
#endregion
}
And then finally there is the CoverView, which I would like to display the collection of Covers and eventually scroll through them. Originally I was trying this with a panel that I will move manually, but I just discovered the FlowObjectPanel so I am trying that:
public partial class CoverView : UserControl
{
#region Members & Constructor
private Covers vCovers;
public CoverView()
{
InitializeComponent();
SetStyle(ControlStyles.DoubleBuffer, true);
this.vCovers = new Covers();
}
#endregion
#region Properties
[System.ComponentModel.Browsable(false)]
public Covers Covers
{
get
{
return this.vCovers ;
}
}
#endregion;
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
vCovers[0].Visible = true;
vCovers[0].Parent = this;
vCovers[0].Location = new Point(0, 0);
}
}
I could do a direct paint, but I do want the Cover objects to be selectable so I may have to stick with this path for the moment. The list may get long tho, so I will give your suggestion some thought.
Anyhoo, I do not know how to get the Covers to show up in the CoverView control. Any help is appreciated ! Thank you !
Andy
|
|
|
|
|
Alright, first of all, I think you're making your job bigger than it has to be with the Covers class. It looks to me like you can use a generic list<t> for what you're doing there. This may save you casting as well. Always use generics if they fit your processing concept, because type safety eliminates casting, which results in economy and speed. The only time I don't use generics is when I have an exceptional circumstance which generics cannot conveniently/appropriately handle.
It is not clear from what you've said so far that your concept for accomplishing your goals is sufficiently refined. Are you embedding your collection/list into an outer composite class which will handle your add method? My initial thinking would be to do so; and I would most likely use that class to handle the basic drawing surface. This would also allow you to hide all the internal members you don't want your clients exposed to. The appropriate base class for your project may be Control. You only need to move up the tree for further behavior if you can best take advantage of (or require) prebuilt features such as scrolling provided by a higher, existent class.
This outer class needs to handle adding and drawing by calling into your list. If you need to assign your images to a picture class which can be selected (or which eliminate having to write specialized code to detect object specific events), you need to pick the class on merits decided by the facts it does more of the things already for you than other classes -- without providing excessive functionality that bloats its footprint.
You may have a basic conceptual problem with Parent assignment (next to last line). What you need to understand is your *display* class (PictureBox? or whatever) has to be parented by your display surface (root Control or Panel for instance). You are making your collection item parented by a UserControl instance, but there is nothing here that tells me you have made your collection item a class which can display an image, and you haven't shown any way that an image is assigned to the collection item class, either.
You need to design a basic process to perform these tasks, and generally such a process must go something like this (envision having to manually do what your code has to do, and that will spell out the process to you):
Your base control probably will need an Add method which inserts or appends a new member in your internalized list/collection. You may also provide susupend and resume methods which allow you to add multiple list members and only draw once at the conclusion of mass member propagations.
The add method assigns an image to the list member object. If that object displays your image for you, then your drawing method decides the position of the object and adds it to the controls array of your root object to set Parent. This in effect draws the object (because internalized drawing methods of the base class do this for you). You probably will not want to try to invoke drawing by calling invalidate.
If on the other hand you choose simply to maintain images in the list and draw them directly to the surface (faster and more efficient), then your Add method draws the image to the surface instead of adding an object to the Controls array.
Incidentally, even when you are double buffering, you do not necessarily have to trigger drawing by calling Invalidate() -- and it may be undesirable to rely on Invalidate(). The IDE sometimes ignores calls to Invalidate(), as it does with other calls such as OnEnabledChanged()/OnSystemColorsChanged(), and this of course can lead to frustrating and costly development issues if you rely on Invalidate().
If you assign your image to the background image of an object however (dimensioned and configured to draw only the image), this *will* trigger Invalidate() under all conditions -- so this is perhaps a more robust approach.
So get your process assigning images to members and drawing them. These vitals are missing from your example.
|
|
|
|
|
Mike,
Wow. Thank you very much for such a detailed reply. It will take me a little time to digest it all. I've been making the VB6 -> C#.NET transition for the last 2 months and it's been quite a ride.
My whole intention is to show a sliding list of Album Covers (thumbnails from a database) w text below that I can select. That is about it. Drawing to the surface of a panel for speed sounds like a great idea, as there will be mass populating of the control at times.
Thx again,
Andy
|
|
|
|
|
You are quite welcome.
Personally, I'm not really hot about .NET being the best way to get such jobs done. If you're changing tools, C++ is a really stable career move. Whether it would work best for what you're doing depends on what you're doing -- but frankly, there isn't much that C++ isn't superior for (even if C# is a great step ahead in certain areas such as header-free development).
In any case, your project touches on a number of things I have to do rather regularly. Stress generics (no matter the development tool). Go light with your resource footprint. Much is said here about certain C# drawing techniques (or technologies) being slow, but you can get around that, particularly with double buffering. The usual requisite approach is to draw off-screen first -- then iterate your generic list to get the job done.
|
|
|
|
|
Hello..
Example:
there are 2 textbox, where i'll type a numeric value
this is the value in the first 2 textbox,
textBox1=500
textBox2=1000
then in textBox3 the sum of the 2 values in the textbox should be automatically generated without triggering it with a button.
Example, i just finish typing those numbers and when i'll press tab in my keyboard,
texBox3 should display=1500
how will i code it?
thanks.
|
|
|
|
|
private void textBox2_Leave(object sender, System.EventArgs e)
{
textBox3 = Convert.ToString( Convert.ToInt64(textBox1.Text)+Convert.ToInt64( textBox2.Text));
}
rahul
|
|
|
|
|
The above function is not a correct one... It ll give an error "Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'".
To correct that,
assign the converted string to the textbox3's text.
textBox3.Text = Convert.ToString( Convert.ToInt64(textBox1.Text)+Convert.ToInt64( textBox2.Text));
Thanks & Rgds,
Sri..
|
|
|
|
|
That is just a question of common sense
rahul
|
|
|
|
|
I have a class which descends from Control and features a Bitmap property. It is my impression that it is my control's responsibility to call Dispose() on the example f_BitmapField in the commented out call of the following snippet. If I deploy this call (remove the comment instructions), there is no resource issue at run time destruction, but if this control is placed on a parent control, then when I delete the parent control at design time (without first deleting my child control) I get an ambiguous error stating only that a parameter is invalid. A later dialog is sometimes raised which refers to the property, not the field — suggesting that an invalid reference to the property exists. No Finalize method is deployed, and no further dispose processes refer to the field or resources which can be associated with it at disposal.
Can anybody explain this behavior? Is it not theoretically the control's responsibility to call Dispose() on the bitmap field as in the commented lines here?
I am beginning to wonder if the IDE isn't mishandling the proper implementation — forcing me to write the wrong code (omit dispose) so that I get acceptable design time behavior. Run time behavior doesn't seem to be affected. I don't feel comfortable about the required implementation. Maybe someone knows there is a different, explicit pattern to follow here?
protected override void Dispose( bool disposing )
{
if ( disposing )
{
}
base.Dispose( disposing );
}
|
|
|
|
|
I'm new to learning C# and I don't know what all the error messages mean. Yet. Can somebody give me a clue as to what the following means. And maybe what I need to do to fix it. Thanks in advance for any information.
"An object reference is required for the nonstatic field, method, or property"
|
|
|
|