|
You need to call ToString() before adding it to the Items collection.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I've decided to go a different route (see post above), but thanks for the help anyways.
- monrobot13
|
|
|
|
|
Coming back to the original problem, you can also fill a listbox or combobox by setting the datasource to any object that implements the interface IList.
I had the problem,that I wanted the ValueMember property differently set to the DisplayMember. With the collections Add() method this is not possible.
So I defined a simple class:
internal class clsName
{
private string _longname;
private int _uid;
public string LongName {get {return _longname;} set {_longname = value;}}
public int UID {get {return _uid;} set {_uid = value;}}
public clsName (string lname, int uid)
{
_longname = lname;
_uid = uid;
}
}
and filled the combobox with an arraylist (the parameters come from a xml file):
[...]
_arrNames.Add(new clsName(nav2.Value,System.Convert.ToInt32(iterator.Current.GetAttribute("UID",nav.NamespaceURI))));
[...]
The combobox datasource can then be set to the arraylist and the members to the appropriate custom class properties.
[...]
cb.DataSource = _arrNames;
cb.DisplayMember = "LongName";
cb.ValueMember = "UID";
[...]
That's all and the list is filled with the strings plus the value is set to what I need in the combobox event handler later in the application.
Wolfgang
|
|
|
|
|
There are 2 ways to do this, one of which you have already mentioned.
Firstly you can use the DisplayMember property:
this.checkedListBox1.DisplayMember = "Test"; <br />
Alternatively, as you mentioned, override the ToString() method. Most list type controls use this as the default DisplayMember when it is not set explicitly:
public override string ToString()
{
return this.Test;
}
I'm not sure why this did not work for you before.
Both of these methods worked in a quick demo i wrote up.
|
|
|
|
|
Hi,
I'm new to this Web services thing..., I've been reading a doc that was made by Microsoft and IBM about security... but I'm not an expert in that area...
It seems that SOAP is a layer that has nothing to do with security that would be handled by un upper layer... does this mean that just using SSL would solve my problems ? I have read that is possible to avoid using an SSL line just by having all the encryption thing inside the webservice ( and if the caller has own some password or libraries from us) how does this work ?
Sorry... the terms that I have used are not very profesionals , greetings
Braulio
|
|
|
|
|
There are different ways you can enforce security for a web service.
It can be SSL or it can be something like modifying the soap header for custom authentication.
SOAP intentionally leaves this area upto the implementor (to my knowledge), you can get more info about web services security from here[^]
Hope this helps.
Cheers,
Kannan
|
|
|
|
|
I asked a similar question before, but never really received a response. I'd like to know how to access the controls, variable, etc on one form from another. In VB you can do something like this:
Form1.TextBox1.Text = Form2.TextBox2.Text What I'm wondering is how can I do this in C#? Is it possible?
Thanks in advance.
- monrobot13
|
|
|
|
|
Hi,
It depends if the variable has been declared public or not, take a look in the code if TextBox2 has been declared as public. I think you can use that
|
|
|
|
|
|
Hello all, hope all is well,
Here is a link to the complete application in question all zipped up, question below: Date Validator
Ok, I wrote a small windows form's app to use as a front end test harness for a simple little date validation class that I am working on. I need the date class for a web service that I am working on, and I needed a way to just test that class so I wrote this little front end app. My compiled app is only 9kb; small. When I run the app it takes up 10+ meg of memory to run; BIG. Now I am fairly new to C# and .NET, but to me that seems like a LOT of over head for such a small and simple app.
I was wondering if some of you more experienced developers out there could take a look and see what I can do to get that foot print down some. Also what are some ways that I can make the worker class (DateValidator.cs) of this run better. The project posted below has two main classes broken apart, one for the form part and one for the class that I hope to be able to reuse in other .Net apps.
1. frmDateInput.cs
2. DateValidator.cs
Here is another link to the complete application all zipped up: Date Validator
I would post the code from each class here but that would be a LOT to read through.
Thanks in advance,
Bill K.
|
|
|
|
|
I thought I would just post these each in their own post so that people can read them with out having to down load the source.
========================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DateValidator
{
public class frmDateInput : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtDate;
private System.Windows.Forms.Label lblDateFormat;
private System.Windows.Forms.Button btnCheckDate;
private System.Windows.Forms.Label lblDateStatus;
private System.Windows.Forms.Label lblDateStatusTag;
private System.ComponentModel.Container components = null;
public frmDateInput()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.txtDate = new System.Windows.Forms.TextBox();
this.btnCheckDate = new System.Windows.Forms.Button();
this.lblDateFormat = new System.Windows.Forms.Label();
this.lblDateStatus = new System.Windows.Forms.Label();
this.lblDateStatusTag = new System.Windows.Forms.Label();
this.SuspendLayout();
this.txtDate.Location = new System.Drawing.Point(16, 17);
this.txtDate.Name = "txtDate";
this.txtDate.Size = new System.Drawing.Size(176, 20);
this.txtDate.TabIndex = 0;
this.txtDate.Text = "";
this.btnCheckDate.Location = new System.Drawing.Point(208, 16);
this.btnCheckDate.Name = "btnCheckDate";
this.btnCheckDate.Size = new System.Drawing.Size(96, 23);
this.btnCheckDate.TabIndex = 2;
this.btnCheckDate.Text = "Check Date";
this.btnCheckDate.Click += new System.EventHandler(this.btnCheckDate_Click);
this.lblDateFormat.Location = new System.Drawing.Point(16, 44);
this.lblDateFormat.Name = "lblDateFormat";
this.lblDateFormat.Size = new System.Drawing.Size(100, 16);
this.lblDateFormat.TabIndex = 3;
this.lblDateFormat.Text = "MM/DD/YYYY";
this.lblDateStatus.Location = new System.Drawing.Point(88, 72);
this.lblDateStatus.Name = "lblDateStatus";
this.lblDateStatus.Size = new System.Drawing.Size(216, 16);
this.lblDateStatus.TabIndex = 4;
this.lblDateStatusTag.Location = new System.Drawing.Point(16, 72);
this.lblDateStatusTag.Name = "lblDateStatusTag";
this.lblDateStatusTag.Size = new System.Drawing.Size(72, 16);
this.lblDateStatusTag.TabIndex = 5;
this.lblDateStatusTag.Text = "Date Status:";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(320, 94);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.lblDateStatusTag,
this.lblDateStatus,
this.lblDateFormat,
this.btnCheckDate,
this.txtDate});
this.Name = "frmDateInput";
this.Text = "Date Validator";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new frmDateInput());
}
private void btnCheckDate_Click(object sender, System.EventArgs e)
{
if(txtDate.Text != string.Empty)
{
int retStatus = DateValidator.parseDate(txtDate.Text);
switch(retStatus)
{
case 1:
lblDateStatus.Text = "This date is valid!";
break;
case 0:
lblDateStatus.Text = "This date is NOT valid, reason unknown!";
break;
case -1:
lblDateStatus.Text = "The month is not correct!";
break;
case -2:
lblDateStatus.Text = "The day is not correct!";
break;
case -3:
lblDateStatus.Text = "The year is not correct";
break;
case -4:
lblDateStatus.Text = "The date string tested was not complete!";
break;
}
}
else
{
MessageBox.Show("A date is required!", "Error!");
}
}
}
}
========================================
Thanks,
Bill K.
|
|
|
|
|
I thought I would just post these each in their own post so that people can read them with out having to down load the source.
========================================
using System;
namespace DateValidator
{
public class DateValidator
{
public static int parseDate(string txtDate)
{
int theMinYear = 2000;
int theMaxYear = 2020;
string[] dateElements = txtDate.Split(new Char[] {'/'});
if(dateElements.Length == 3)
{
int theMonth = Convert.ToInt32(dateElements[0],10);
int theDay = Convert.ToInt32(dateElements[1],10);
int theYear = Convert.ToInt32(dateElements[2],10);
if(theMonth > 0 && theMonth < 13)
{
if(theYear > theMinYear && theYear < theMaxYear)
{
switch(theMonth)
{
case 1:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
case 2:
if((theYear % 4 == 0 && theYear % 100 != 0) || theYear % 400 == 0)
{
if(theDay > 0 && theDay < 30)
{
return 1;
}
else
{
return -2;
}
}
else
{
if(theDay > 0 && theDay < 29)
{
return 1;
}
else
{
return -2;
}
}
break;
case 3:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
case 4:
if(theDay > 0 && theDay < 31)
{
return 1;
}
else
{
return -2;
}
break;
case 5:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
case 6:
if(theDay > 0 && theDay < 31)
{
return 1;
}
else
{
return -2;
}
break;
case 7:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
case 8:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
case 9:
if(theDay > 0 && theDay < 31)
{
return 1;
}
else
{
return -2;
}
break;
case 10:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
case 11:
if(theDay > 0 && theDay < 31)
{
return 1;
}
else
{
return -2;
}
break;
case 12:
if(theDay > 0 && theDay < 32)
{
return 1;
}
else
{
return -2;
}
break;
default:
return 0;
break;
}
}
else
{
return -3;
}
}
else
{
return -1;
}
}
else
{
return -4;
}
}
}
}
========================================
Thanks,
Bill K.
|
|
|
|
|
codeweenie wrote:
My compiled app is only 9kb; small. When I run the app it takes up 10+ meg of memory to run;
Remeber all the runtime dll's you are referenceing. You need to keep that in mind too. It's not your code, just the nature of the .Net runtime and other such VM's.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Remeber all the runtime dll's you are referenceing. You need to keep that in mind too. It's not your code, just the nature of the .Net runtime and other such VM's.
That makes complete sense, and based on that, which of the using statements can I get away with NOT using? I guess I can just comment them out one at a time and see which break's it. Here are the ones that I am using currently:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
Based on how simple my little beginner app is which can I get away with NOT using?
Thanks,
Bill K.
|
|
|
|
|
Those are namespaces, not referenced assemblies...
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Those are namespaces, not referenced assemblies...
Oh boy, I am in trouble then. Can you explain to me what I need to kill in my code or what is being referenced that would be causing it to be huge? I am trying to learn here. Thanks for your cotinued help, it really does make a difference. Anyway, what should I kill, by the way I know there are easier ways to do date validation, but I am trying to use this app as a learning tool for myself. I guess it's working... and hey maybe some others will learn a thing or two from it too.
Thanks,
Bill K.
|
|
|
|
|
codeweenie wrote:
Can you explain to me what I need to kill in my code or what is being referenced that would be causing it to be huge?
If its a WInForms app, pretty much nothing. They tend to take about 20mb. A console app, about 10mb.
The referenced assemblies are the ones in the solution explorer under your project, remove the ones you dont need. All assemblies are optional, except for the core assemblies, but those you cant change.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Does anyone have some neat trick to make a form not to steal focus from another form??
what i want to do is to create a popup window that does not steal focus from the form that opens it...
ive tried to mess with the wndproc , created my own real subclasser using setwindowlong (incase the winforms wndproc didnt get all messages)
ive tried various window styles...
and nothing works...
the closest i got was to send a wm_ncactivate to the parent form when the popup form recived focus..
but thats not a very clean way to solve it...
//Roger
|
|
|
|
|
Cannot remember for sure, but I think a tool window does not take the focus.
I know it is a pain in the lower sections to deal with. Would have been nice if Microsoft provided a simple window style for this where it can be on the outside of the window client area and still not take focus. A few months ago I spent a lot of time trying to figure an easy way around this to build drop down grid combo where it would appear like a combo box but when you dropped it, a grid would appear. Got tied of it always stealing focus. Tried many different things, all the way to have the desktop be the parent but still no go.
Good luck, it wore me out Would be nice if you found a way that you could drop me a note, still would like to build that drop down grid combo
Rocky Moore <><
|
|
|
|
|
oke , this didnt solve the problem.
anyone else have some idea??
//Roger
|
|
|
|
|
I'm looking for this too, I have a custom control, which looks like combo box, (using uxtheme.dll to drawn the combobox button, seperate textbox, and a listbox to have a color picker, vs.net style) and it works bloody well, all ownerdrawn. But the listbox is on a form, that pops up like a combobox dropdown, would be nice it it was a non-focus form as well
|
|
|
|
|
Hi
any ideas how to DRAW something with xp style?
say eg a button , if i would like to draw a xp styled button on a graphics surface,
is there any neat xp api one could use?
//Roger
|
|
|
|
|
I think version 1.1 of the framework includes an property by the name "Visual Styles" which would help you achieve the winxp look and feel.
If you are talking about win32 api which you can use through p/invoke, then there are some 30+ functions which deals with themes alone.
Maybe you can start with something like "DrawThemeBackground" or "DrawThemeEdge", you can get more info' from msdn on these functions.
Hope this helps.
Cheers,
Kannan
|
|
|
|
|
Thanks ,
i will read some on the xp theme drawing api..
(had no idea there was such apis...)
//Roger
|
|
|
|
|
Have anyone seen data object broker like ObjectRelationalBridge
written in managed code for .NET?
(db.apache.org/ojb).
/Mario
PS.
I did not find any forum this question might fit, please excuse me if this is completely incorrect forum for this question!
DS.
|
|
|
|