|
Hi,
im using propertygrid and trying to show boolean property with other string values than true/false,
i made boolenconverter for this, it works fine when i use combobox to change value, but i get inner propertygrid error when i doubleclick to change value in propertygrid:
Invalid property value!
Details: Cannot widen from target type to primitive type.
<br />
public class BaseProps{<br />
<br />
private bool test;<br />
<br />
[TypeConverter(typeof(BoolNameConverter2))]<br />
public bool Value {<br />
get {return test;}<br />
set {test = value;}<br />
}<br />
<br />
}<br />
<br />
<br />
public class BoolNameConverter2 : StringConverter<br />
{<br />
<br />
private const string m_trueDisplayName = "on";<br />
private const string m_falseDisplayName = "off";<br />
<br />
public override bool CanConvertTo(ITypeDescriptorContext context,<br />
System.Type destinationType) <br />
{<br />
if (destinationType == typeof(bool))<br />
return true;<br />
<br />
return base.CanConvertTo(context, destinationType);<br />
}<br />
<br />
public override object ConvertTo(ITypeDescriptorContext context,<br />
CultureInfo culture, <br />
object value, <br />
System.Type destinationType) <br />
{<br />
if (value is bool && destinationType == typeof(System.String)) {<br />
return (bool)value ? m_trueDisplayName : m_falseDisplayName;<br />
}<br />
return base.ConvertTo(context, culture, value, destinationType);<br />
}<br />
<br />
public override bool CanConvertFrom(ITypeDescriptorContext context,<br />
System.Type sourceType) <br />
{<br />
if (sourceType == typeof(string))<br />
return true;<br />
<br />
return base.CanConvertFrom(context, sourceType);<br />
}<br />
<br />
public override object ConvertFrom(ITypeDescriptorContext context,<br />
CultureInfo culture, object value) <br />
{<br />
if (value is string) {<br />
return (string)value == m_trueDisplayName ? true : false;<br />
} <br />
return base.ConvertFrom(context, culture, value);<br />
}<br />
<br />
public override bool GetStandardValuesSupported(<br />
ITypeDescriptorContext context) <br />
{<br />
return true;<br />
}<br />
<br />
public override StandardValuesCollection<br />
GetStandardValues(ITypeDescriptorContext context) <br />
{<br />
return new StandardValuesCollection (new string[]{m_trueDisplayName, m_falseDisplayName});<br />
} <br />
<br />
public override bool GetStandardValuesExclusive(<br />
ITypeDescriptorContext context) <br />
{<br />
return true;<br />
}<br />
<br />
}<br />
<br />
What could be the problem? Has anybody had similar problem and has solution? How to fix it?
Thanks
Deglimmer
|
|
|
|
|
|
hi
in my app, i have two forms, in form1, i have a button and gridview and a public method as 'LoadData' as follow :
public void LoadData()<br />
{<br />
using (SqlConnection con = new SqlConnection("Data Source=server;Initial Catalog=northwind;User Id=sa;Password=1;"))<br />
{<br />
SqlCommand cmd = new SqlCommand("select * from customers", con);<br />
SqlDataReader dr;<br />
DataTable dt = new DataTable();<br />
con.Open();<br />
dr = cmd.ExecuteReader();<br />
dt.Load(dr);<br />
con.Close();<br />
this.gridControl1.DataSource = dt.DefaultView;<br />
}<br />
}
in button_click event, i show form2 as follow :
private void simpleButton1_Click(object sender, EventArgs e)<br />
{ <br />
Form2 frm = new Form2();<br />
frm.Show();<br />
}
in form2, i have only one button, i want when i click this button, create object from form1 and calling LoadData() method to fill gridView as follow :
private void simpleButton1_Click(object sender, EventArgs e)<br />
{<br />
Form1 frm = new Form1();<br />
frm.LoadData();<br />
}
but in runTime, when i click button in form2, gridView does not fill, i trace my app and i saw frm.LoadData() was correctly work but gridView does not fill, where does my problem and how to solve it ?
thanks
|
|
|
|
|
So you have: Form1 with Button 1 and Form2 with Button 2 - if you klick Button 1, a new Form2 window should appear and if you then click on Button 2 in it, the first form (Form1) shall Load the data right?
Ok you will have to do something like this:
in Form2 declare a public function SetForm1 - that sets an internal variable to an object of Form1, then in the first button click use:
<br />
Form2 frm = new Form2();<br />
frm.SetForm1(this);<br />
frm.Show();<br />
and in Buttonclick of Form2:
<br />
_form1Var.LoadData();<br />
The problem is simple: in your code you create a new Form1 object (that you will never see - you never use it's Show-method) and fire LoadData against this!
Bye the way: you should not interweave two forms in such a way - use events of public functions for such tasks.
|
|
|
|
|
thanks for reply,
my problem was solved.
regards
|
|
|
|
|
<br />
<br />
private Form1 _form1;<br />
public void SetForm1(Form1 obj)<br />
{ _form1 = obj; }<br />
<br />
Then you can use
_form1.LoadData()
inside your Button_Click - event
|
|
|
|
|
Hi
I need to write an IF statement which checks if a session contains a _
how would i go about doing this
thanks
|
|
|
|
|
Please don't post questions twice, your last post comes down to the same question and I answered it there.
Standards are great! Everybody should have one!
|
|
|
|
|
|
How to get the number of all elements in XML file using DOM?
|
|
|
|
|
Hi
I have the following code which checks what the last number is in a database field after the _ and then adds 1 to it. however i need to add an extra bit of code in to check if a number exisits there already as the field could be: xxxx~xxx_01 or it could just be xxxx~xxx without the underscore. if its the latter then it will need to start from 1 and incrment up from there adding an underscore to the field where as at the moment it checks if there is a 1 there already,
any suggestions?
hope this makes sense, comment if not
cheers
SqlCommand cmd17 = new SqlCommand(test0002, con2);
StringBuilder htmlStr_room_code2 = new StringBuilder("");
SqlDataReader reader2 = cmd17.ExecuteReader();
while (reader2.Read())
{
htmlStr_room_code2.Append(reader2["room_code"]);
}
lbtest2.Text = htmlStr_room_code2.ToString();
Session["sessiontest1"] = lbtest2.Text.ToString();
string db = Session["sessiontest1"].ToString(); // "jh00~pr11_01";
string[] split = db.Split('_');
string s_number = split[1];
int i_number = Int32.Parse(s_number);
i_number++;
s_number = i_number.ToString();
db = split[0] + "_" + s_number;
|
|
|
|
|
Once you have your db string you can use if(db.Contains("_")) and go from there.
Standards are great! Everybody should have one!
|
|
|
|
|
I am developing an windows application and i want that when system starts application automatically run.
I know that may be done by using windows services but i am unable to do that.......
So please help
|
|
|
|
|
The answer's on the first page I got when searching on
Google[^] :S.
Standards are great! Everybody should have one!
|
|
|
|
|
|
as you've got answers concering windwos services:
I don't think you want to write a service-app. (services shouldn't use GUIs! - aka forms etc.) - you just want to start the app on starup? - Well put a link into your autostart (startup whatever) - folder in your start-menu!
|
|
|
|
|
... or (if the service is unecessary) put the path to your app in the registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Value name: Your App
Value Data: Your_App_Path
|
|
|
|
|
i have a windows control which is to be loaded on a webpage(.aspx page)
control is loaded with the aid of "object" tag
the control is developed in C#.net(managed code basically)
the control makes use of the system resources and even makes use of some other dll's too
problem:
the control fails to load on the webpage
first solution tried:
change the .net security with the aid of caspol
so i tried giving full trust to all code
this worked fine and the control got loaded.
however this worked fine only when the webpage was a part of the default website in IIS
in case if the webpage which hosts the control is a part of a virtual website apart from the default website
the control is failing to load
so what might be the problem...??
from some of the blogs which i read...the .net tries to give trust
to assemblies based on from where the assembly is getting streamed
so i also tried to load the control by making this site a trusted one
still the control didn't load
any idea...as to might b wrong....
|
|
|
|
|
naveen1382 wrote: have a windows control which is to be loaded on a webpage
Right there is probably your problem...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Paul Conrad wrote: Right there is probably your problem...
Why's that then?
C# has already designed away most of the tedium of C++.
|
|
|
|
|
I've been working on something very similar recently, and having almost identiacal problems!
I'm a lil confused by your post however - what do you mean by Virtual Website? Do you mean that the folder you're hosting the control in is a virtual directory, configured in IIS?
If this is the case, you shouldn't be having any problems - but of course we always do! Some things to check would be to ensure that the control is actually being served by IIS - I had issues with the control not being downloaded. Simplest way to check is to clear out temp internet files, navigate to the page, then check that the .dll has appeared in the folder (View files from IE Tools-> Internet Options) If it hasn't appeared, then the problem is with IIS, if it has, then probably a security issue.
If it isn't being served, check that the application's Execute Permissions (IIS Admin -> Site Properties) are set to Scripts only - i had mine set to Scripts and Executables, so when requested, IIS was treating my dll as an exe, and attempting to run it rather than serve to the client.
If it's a security issue, it may be that the evidence you're using isn't quite right. Most of the docs recommend using strong name evidence. The problem with this is that is causes stack walk problems with the app domain. I used site evidence, at the all code level, by issuing:
caspol -m -ag 1 -site www.mysite.com FullTrust -n MyGroupName
This creates a sub group of the All code group at the Machine level, granting full trust to anything from www.mysite.com.
Hopefully this helps
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Hi
I have the following code which is supposed to increment 1 but it seems to be incrementing by 3
any suggestions?
cheers
string maxquery = "Select max(activity_order) from roomactivitylk where room_code = 'v1106'";
int max;
SqlCommand cmd15 = new SqlCommand();
cmd15.Connection = con;
cmd15.CommandText = maxquery;
max = Convert.ToInt32 (cmd15.ExecuteScalar());
max = max + 1;
++max;
max++;(needs to only be one of these)
modified on Monday, December 10, 2007 4:41:39 AM
|
|
|
|
|
Jamie1985 wrote: max = max + 1;
++max;
max++;
Each of these lines increments max by one.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Jamie1985 wrote: max = max + 1;
++max;
max++;
Why do you write like that?
use only one. eg. max++;
|
|
|
|
|
thanks managed to sort it, you were right
cheers
|
|
|
|