|
01: string strStore
02: ListItemType oType = ((ListItemType)e.Item.ItemType);
03: if ((oType == ListItemType.EditItem))
04: {
05: Response.Write("The ItemDataBound Command has been fired");
06: DropDownList listStore = ((DropDownList) e.Item.FindControl("ddlStores"));
07: strStore = ((DropDownList)(e.Item.FindControl("ddlStores"))).SelectedItem.Text;
08: Response.Write (strStore);
09:
10: listStore.Items.IndexOf(listStore.Items.FindByText(strStore));
11: Response.Write(listStore.Items.IndexOf(listStore.Items.FindByText(strStore)));
12: }
I'm having difficulty trying to read your code here. I've numbered the lines for ease of reference.
Line 1: Missing semi-colon;
Line 2: e.Item.ItemType[^] already returns an object of type ListItemType so I am curious as to why you are casting it.
Line 5: I am assuming this is for debugging only. If so, a better mechanism would be setting up tracing. See: Enabling Tracing for a Page[^] and Writing Trace Messages[^]
Line 7: Finding the control again is redundant here because you did that on line 6. Change the line to strStore = listStore.SelectedItem.Text
Line 8: See previous comments on tracing
Line 10: You perform an IndexOf operation but do not store the value anywhere.
Line 11: You perform the same IndexOf operation again.
Now, to answer your question:
On line 6 you get the DropDownList, once you have this you can use the SelectedIndex[^] property to get the index of the selected item.
Does this help?
Do you want to know more?
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
I did as you told me and still having problems. Also when I have to go back in edit mode I must have the dropdownlist index preselected. But one thing at a time. Below the code is the error, this is why I cast it. Now, if I want to save the index how to I go about doing so. I appreciate any help. Thanks.
private void DataGridUserManagementID_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string strStore;
ListItemType oType = ((ListItemType)e.Item.ItemType);
if ((oType == ListItemType.EditItem))
{
DropDownList listStore = e.Item.FindControl("ddlStores");
strStore = listStore.SelectedItem.Text;
Response.Write(strStore);
}
}
Server Error in '/MSPOS' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.DropDownList'
Source Error:
Line 178:
Line 179:
Line 180: DropDownList listStore = e.Item.FindControl("ddlStores");
Line 181: strStore = listStore.SelectedItem.Text;
Line 182: Response.Write(strStore);
Source File: c:\inetpub\wwwroot\MSPOS\Administrator.aspx Line: 180
Mathieu Cupryk
|
|
|
|
|
In line 180 of your source code you need to cast to a DropDownList.
e.g.
DropDownList listStore = (DropDownList)(e.Item.FindControl("ddlStores"));
In case there was confusion with my earlier post. The line of your source code that reads: ListItemType oType = ((ListItemType)e.Item.ItemType); is the line that does not need the cast, as ItemType already returns a value of type ListItemType
Do you want to know more?
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Thank you. I still have a problem when I return to edit mode the index for the dropdownlist starts at 0. How do I set this when we change the index. Can u help me please.
private void DataGridUserManagementID_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
string strStore;
ListItemType oType = (e.Item.ItemType);
if ((oType == ListItemType.EditItem))
{
DropDownList listStore = ((DropDownList) e.Item.FindControl("ddlStores"));
strStore = listStore.SelectedItem.Text;
}
}
|
|
|
|
|
macupryk wrote:
I still have a problem when I return to edit mode the index for the dropdownlist starts at 0
I'm not quite with you there. All collections in the .NET framework are zero based.
macupryk wrote:
How do I set this when we change the index
I still don't quite understand. How do you set what when the index is changed?
The only thing that I can think that you mean is that the index does not change in the editor - but I cannot imagine why anyone would want that, or that it would be useful. The index can only change within a running program.
Do you want to know more?
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
hi
I need to print text but the font height has to be configurable.
I know I can change the font size at run time, but changing the font size changes both height and width proportioally.
For example I need to increase the witdh X2 ,and the height X 4.
Thanks!
|
|
|
|
|
Fonts are graphical representation of characters and are designed to resize proportionally. If you need to resize them disproportionately, then you'll need to transform them.
One way would be to either create a new Graphics device or to adjust your math - if possible - to account for the transformation you'll be performing to the Graphics object.
To perform the transformation, you can use a myriad of methods on the Graphics class - all documented in the .NET Framework SDK. One such method follows:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
Test()
{
StretchLabel lbl = new StretchLabel();
Controls.Add(lbl);
lbl.Dock = DockStyle.Fill;
lbl.ScaleHeight = 4f;
lbl.Font = new Font(Font.FontFamily, 20f);
lbl.ScaleWidth = 2f;
lbl.Text = "Sample";
Text = "Sample";
}
}
class StretchLabel : Label
{
SizeF size = SizeF.Empty;
float scaleWidth = 1f;
float scaleHeight = 1f;
[DefaultValue(1f)]
public float ScaleWidth
{
get { return scaleWidth; }
set { scaleWidth = value; }
}
[DefaultValue(1f)]
public float ScaleHeight
{
get { return scaleHeight; }
set { scaleHeight = value; }
}
protected override void OnTextChanged(EventArgs e)
{
using (Graphics g = CreateGraphics())
size = g.MeasureString(Text, Font, (SizeF)Size);
base.OnTextChanged(e);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.ScaleTransform(scaleWidth, scaleHeight, MatrixOrder.Append);
g.DrawString(Text, Font, new SolidBrush(ForeColor), PointF.Empty);
base.OnPaint(e);
}
} Pay close attention to the Graphics.ScaleTransform , which I recommend reading about in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
I think I got it to do what I want. Here is the code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace FontSizeTest
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtH;
private System.Windows.Forms.TextBox txtW;
private System.Windows.Forms.TextBox txtStr;
private System.Windows.Forms.Button btnGo;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.panel2 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtH = new System.Windows.Forms.TextBox();
this.txtW = new System.Windows.Forms.TextBox();
this.txtStr = new System.Windows.Forms.TextBox();
this.btnGo = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// panel2
//
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this.label1);
this.panel2.Controls.Add(this.txtH);
this.panel2.Controls.Add(this.txtW);
this.panel2.Controls.Add(this.txtStr);
this.panel2.Controls.Add(this.btnGo);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(0, 165);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(336, 80);
this.panel2.TabIndex = 12;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.Location = new System.Drawing.Point(164, 30);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(128, 16);
this.label2.TabIndex = 16;
this.label2.Text = "Height (Millimeters)";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.Location = new System.Drawing.Point(20, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(128, 16);
this.label1.TabIndex = 15;
this.label1.Text = "Width (Millimeters)";
//
// txtH
//
this.txtH.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtH.Location = new System.Drawing.Point(164, 54);
this.txtH.Name = "txtH";
this.txtH.Size = new System.Drawing.Size(64, 20);
this.txtH.TabIndex = 14;
this.txtH.Text = "15.00";
//
// txtW
//
this.txtW.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtW.Location = new System.Drawing.Point(20, 54);
this.txtW.Name = "txtW";
this.txtW.Size = new System.Drawing.Size(64, 20);
this.txtW.TabIndex = 13;
this.txtW.Text = "80.00";
//
// txtStr
//
this.txtStr.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtStr.Location = new System.Drawing.Point(20, 6);
this.txtStr.Name = "txtStr";
this.txtStr.Size = new System.Drawing.Size(268, 20);
this.txtStr.TabIndex = 12;
this.txtStr.Text = "This is the test string. change it or the box size";
//
// btnGo
//
this.btnGo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnGo.Location = new System.Drawing.Point(288, 40);
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(48, 32);
this.btnGo.TabIndex = 11;
this.btnGo.Text = "&Go";
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(336, 165);
this.pictureBox1.TabIndex = 13;
this.pictureBox1.TabStop = false;
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(336, 245);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
void PrintScale(
Graphics gfx,
float widthMM, float heightMM, string text,
Brush color, float xMM, float yMM)
{
xMM /= widthMM;
yMM /= heightMM;
gfx.ScaleTransform(widthMM, heightMM, MatrixOrder.Append);
gfx.DrawString(text, new Font(Font.FontFamily, 1),color,xMM,yMM);
//restore
gfx.ScaleTransform(1/widthMM, 1/heightMM);//, MatrixOrder.Append);
}
void DoPaint2 (System.Windows.Forms.PaintEventArgs e)
{
SizeF sz;
string str5 = txtStr.Text;
int strLen = str5.Length;
float boxW=float.Parse(txtW.Text), boxH=float.Parse(txtH.Text);
float charW, charH;
float scaleX, scaleY;
Pen pen ;
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
sz = e.Graphics.MeasureString(str5,new Font(Font.FontFamily,1)); //Find string length using font of size 1
charH = sz.Height; // character height
charW = sz.Width / strLen; // avg. character width
scaleY = boxH / charH;
scaleX = (boxW/strLen) / charW;
pen = new Pen(Brushes.Red,0.2f);
e.Graphics.DrawRectangle(pen, 5f,5f,boxW,boxH);
PrintScale(e.Graphics,scaleX,scaleY,str5, Brushes.Black,5f,5f);
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
try
{
DoPaint2 (e);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnGo_Click(object sender, System.EventArgs e)
{
pictureBox1.Refresh();
}
}
}
|
|
|
|
|
Hi,
I was making a very simple windows application in C#. the application runs fine when i create a new windows application but when i add a button on the form a problem occurs. Although the application compiles correctly, but when i run the application it gives an exception saying,
"An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll
Additional information: Overflow or underflow in the arithmetic operation."
I am really confused here because i am placing the button on the form using the form designer. i have not even touched the code itself. i also tried to add the button to the form by coding myself but the same problem exists.
please help me i will be really thankful.
bye.
|
|
|
|
|
Try changing your code to the following and seeing if it helps any:
[DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]<br />
public static extern int _controlfp(int n, int mask);<br />
<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
_controlfp(_CW_DEFAULT, 0xfffff);<br />
Application.Run(new Form1());<br />
}
|
|
|
|
|
Something is really weird. What does the code that gets added look like ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hello!
I've used C# and .NET for about a year and i would need some help with books to buy. I need some good books in OOP thinking (not syntax and such, but tips about different approaches to different problems). And also visual c# books that are above beginner level. I would really like the books to be in project-form, meaning it takes you through the stages of several smaller applications/projects.
So if anyone has any tips i would appreciate it!
Thanks!
|
|
|
|
|
Programming Windows with C#
http://www.amazon.com/exec/obidos/tg/detail/-/0735613702/qid=1095869556/sr=1-3/ref=sr_1_3/104-9011139-0631159?v=glance&s=books
A really good windows forms programming book.
Applied Microsoft .NET Framework Programming
http://www.amazon.com/exec/obidos/tg/detail/-/0735614229/qid=1095869620/sr=1-2/ref=sr_1_2/104-9011139-0631159?v=glance&s=books
This one is about .net framework. Highly recommended.
Design Patterns C#
http://www.amazon.com/exec/obidos/tg/detail/-/0321126971/qid=1095869705/sr=1-1/ref=sr_1_1/104-9011139-0631159?v=glance&s=books
This one is more about software design (using patterns). Good stuff on OOP thinking.
|
|
|
|
|
Hi
How can get the information about folders and files on a web server in C#. I want to create a application that will download folders and files from web server.
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Unless the web server is specifically setup to allow you to get the list of files and folders, you're sunk. Now-a-days, for security reasons, 95% of them DON'T let you see this stuff. You'll have to do this using FTP if the site has an FTP server pointed at the same pages.
You could write a web page scraper that would follow and download the files for every link in each page and download every file, keeping track of which directory these files come from on the web server.
But, then again, this has been done many time over. A good example of this kind of work is BlackWidow[^] by Softbyte Labs.
Sites have even developed countermeasures for rippers like this too. Noone wants all of their copyrighted content taken from them without they're permission, now do they?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Another example is Flashget Site explorer feature
|
|
|
|
|
In addition to using FTP like Dave mentioned, you could also try DAV but this isn't not implemented on a majority of servers and is typically authorized only to authenticated users.
A web crawler (not scraper, which grabs content from a page instead of crawling the links like a web crawler) would suffice. Keep a collection of directories and files and do NOT follow <FORM> actions. You're in a world of trouble if you do, and could be held liable for damages (not to mention more difficult parsing is often involved).
But Dave's right; there are serious legal concerns for crawling and caching certain content, much more in the last few years than when the Web first started. Besides, as Dave and the other reply pointed out there's already many programs that do this. Why developer yet another?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi all,
Thanks for your suggestions.
In fact I am new to web programing. I was wondering if we could download through the browser then why not through myown application.
I just want to avoid the windows progress bar while downloading. And also specify certain urls and forget about it. These will be automatically downloaded to the specified folder. Cool ! right ?
Thanks again
Regards
Shiraz
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Downloading has nothing to do with the "browser". You download things from web sites - or just about any remote machine through TCP/IP via sockets.
You can download files without any progress at all. Read about the WebRequest and WebResponse classes, as well as their derivatives like HttpWebRequest and HttpWebResponse . You can also use the easy-to-use WebClient class to download files.
All these classes includes examples in the .NET Framework SDK which was installed with Visual Studio .NET or standalone, however you obtained it. We have also discussed this many times in the past on this forum, so if you want to learn more, click "Search comments" above, but you should read the .NET Framework SDK documentation for those classes and their members first.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
My application goes throught multiple database access.
during this time, the application is frozen since all its resources are dedicated to the task at hand.
Can anyone tell me how, or preferably point me to a tutorial that would explain to me how to connect to a database without freezing the main application screen?
Thanks in advance,
Jon G
www.Gizmocoder.com
|
|
|
|
|
You need to check into threading, this way you can execute your heavy processing on a separate thread from the main UI thread. I'd recommend you start with the Threading Tutorial[^] from the C# Programmer's Reference.
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Hi All,
I have created a class that simulates a MDI form by putting the 'child' inside a panel located in the 'parent' form. I had to do this because we use a custom UI that doesn't work properly with standard MDI forms.
The constructor of the class is something like
SemiMDI(System.Windows.Forms.Form client,System.Windows.Forms.Panel parentArea)
So far I've managed to create the form in the designed area and it works ok. Now the problem is when the parent form's resize event is triggered. I know it could be possible to resize the child by calling a 'rearrange' method in my class, but I would like to do it by subscribing the SemiMDI class to the 'resize method of the parent, so everytime I use my class I dont have to worry about linking the child form to the resize event of the parent.
Any ideas? Subscribing events is what I thought, but I'd like to know if you have a better solution.
Thanks!
|
|
|
|
|
In order to attach a handler, you would have to cast client to your Form type and make sure the handler is accessible (i.e., not private - use internal , perhaps).
When handling events in controls and forms, however, it's better to override the event handlers that are already present. So, if you needed to handle the Resize , it's better to override OnResize :
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
} This has less overhead and gives you a greater amount of control over what happens when an event is fired (because your override is actually called before firing the event; calling base.OnEventName is what eventually may fire the event).
With this in mind, you might consider extending all your MDI child forms from a single class that implements this resizing behavior. That would be a good object-oriented design.
Even if this single base class must delegate resizing code to its MDI parent (perhaps the MDI parent contains information that the MDI children can't access), you must still make sure that the handler is accessible and implementing this code in a single base class makes for a better OO design.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|