|
I want to be able to save myself writing a lot of code and use the CodeDOM to do some dynamic generation. I'll try my best to explain it :-/
I have several classes all which have a "Create" method and all create different windows components for example
Class ButtonControl
{
public static void Create(ButtonValues values, Button button)
{
button.Text = values.Text;
...
}
}
Class LabelControl
{
public static void Create( LabelValues values,Label button)
{
Label.Text = values.Text;
...
}
}
Then i want to be able to dynamically call one of these from a function like
void CreateControl(string TYPE, Control selected)
{
TYPE.Create(values, selected);
}
And i don't have any idea how to pass the parameters like that with the CodeDOM i have little experience with it, any help would be appreciated
|
|
|
|
|
CodeDOM is for generating code, which you can then compile and run.
It sounds like you are looking to create controls at runtime, you might be better served with Activator.CreateInstance(...) and the System.Reflection namespace.
|
|
|
|
|
Thanks, i managed to do it very easily with reflection
|
|
|
|
|
Hi there.
Already I was using PHP .
In PHP we can get program's number line, for example the following code writes 9 in out pot.
1 <?php
2
3
4
5
6
7 8
9 echo __LINE__;
10
11
12
13 ?>
Now , I want to know whether we can get program's number line in C# when the program is running?
Freshman
|
|
|
|
|
M-Dayyan,
AFAIK, I don't think you can. Whats the reason you want to print out the line number?, i am guessing its debugging related?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Hi,
it is possible, but not very easy; there is no predefined symbol as in C/C++.
you can figure out where you are (and how you got there) by reading
Environment.StackTrace; you could even create a method that takes the second
entry (skipping the method itself) to extract the classname, methodname, and
line number.
The line numbers may or may not be present depending on circumstances such
as debug/release build.
|
|
|
|
|
Thanks Luc Pattyn.
Freshman
|
|
|
|
|
you're welcome.
|
|
|
|
|
I must using
StackFrame CallStack = new StackFrame(0, true);
Console.Write("File: " + CallStack.GetFileName() + ",
Line: " + CallStack.GetFileLineNumber());
Freshman
|
|
|
|
|
I am trying to update my Access and I am recieving an Error:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace ProspectorV100
{
public partial class frmProspectMaint : Form
{
OleDbConnection cnADONETConnection = new OleDbConnection();
OleDbDataAdapter daContactsCombo;
OleDbCommandBuilder cbContactsCombo;
DataTable dtContactsCombo = new DataTable();
int row;
long intContactID;
public frmProspectMaint()
{
InitializeComponent();
}
private void frmProspectMaint_Load(object sender, EventArgs e)
{
cnADONETConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Prospector\Database\prospect.mdb";
cnADONETConnection.Open();
daContactsCombo =
new OleDbDataAdapter("Select * From Contacts Order by Last_Name", cnADONETConnection);
OleDbCommandBuilder cbContactsCombo = new OleDbCommandBuilder(daContactsCombo);
daContactsCombo.Fill(dtContactsCombo);
this.LoadSearchBox();
}
private void LoadSearchBox()
{
for (int x = 0; x < dtContactsCombo.Rows.Count; x++)
{
tlsSearch.Items.Add(dtContactsCombo.Rows[x]["Last_Name"].ToString() + ", " +
dtContactsCombo.Rows[x]["First_Name"].ToString());
tlsSearch.AutoCompleteCustomSource.Add(dtContactsCombo.Rows[x]["Last_Name"].ToString() + ", " +
dtContactsCombo.Rows[x]["First_Name"].ToString());
}
}
private void frmProspectMaint_FormClosed(object sender, FormClosedEventArgs e)
{
cnADONETConnection.Close();
cnADONETConnection.Dispose();
}
private void tlsSearch_SelectedIndexChanged(object sender, EventArgs e)
{
row = tlsSearch.SelectedIndex;
intContactID = Convert.ToInt32(dtContactsCombo.Rows[row]["Contact_ID"].ToString());
txtFirstName.Text = dtContactsCombo.Rows[row]["First_Name"].ToString();
txtLastName.Text = dtContactsCombo.Rows[row]["Last_Name"].ToString();
txtCompany.Text = dtContactsCombo.Rows[row]["Company_Name"].ToString();
txtJobTitle.Text = dtContactsCombo.Rows[row]["Job_Title"].ToString();
}
private void tlsSave_Click(object sender, EventArgs e)
{
//If there is existing Data Update it
if (row >= 0)
{
dtContactsCombo.Rows[row]["Contact_ID"] = intContactID;
dtContactsCombo.Rows[row]["Last_Name"] = txtLastName.Text;
dtContactsCombo.Rows[row]["First_Name"] = txtFirstName.Text;
dtContactsCombo.Rows[row]["Company_Name"] = txtCompany.Text;
dtContactsCombo.Rows[row]["Job_Title"] = txtJobTitle.Text;
daContactsCombo.Update(dtContactsCombo);
}
}
}
}
As I stated before I am new to C# and any help would be appreciated.
|
|
|
|
|
kruegersck,
What is the error? and at which line does it happen?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Sorry - I get an SQL Error at the line: daContactsCombo.Update(dtContactsCombo);
Syntax error in query expression '((Contact_ID = ?) AND ((? = 1 AND First_Name IS NULL) OR (First_Name = ?)) AND ((? = 1 AND Last_Name IS NULL) OR (Last_Name = ?)) AND ((? = 1 AND Company_Name IS NULL) OR (Company_Name = ?)) AND ((? = 1 AND Job_Title IS NULL) OR (Job_Title = ?)) AND ((? ='.
Thanks for all your help
|
|
|
|
|
kruegersck wrote: ((? = 1
I don't think it works like that.
kruegersck wrote: ((? =
Definately this won't work, you have two brackets ( for no good reason ) and they are not closed.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
That is the error message I am getting????
|
|
|
|
|
Yes, so the string you're using for your query, is wrong. That is what I am telling you.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
Are there any good examples of doing this using Access?
Thanks Again.
|
|
|
|
|
I'm not sure what you mean by 'doing this', it looks to me like you're asking a SQL question and all you need to do is close your brackets. Where is the issue ?
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
Assumption , we have a TreeView in C# form and each node of TreeView contains web address.
Now, I want drag a node into the IE browser as IE opens its web address.
How can we do it ?
Freshman
|
|
|
|
|
I guess the question you need to ask is, what format of drag and drop, if any, does IE support. If it has support for something like this, you need to write code to conforms to what IE expects.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
Thank you Christian.
Christian Graus wrote: you need to write code to conforms to what IE expects.
It is my problem exactly
Can you help me ?
Freshman
|
|
|
|
|
A quick google leads me to believe that IE has a drop event handler, so if you had IE in your own window, as a control, you could handle it. I don't see anyting else, but if you try to google it, you may find something.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
OK, Thanks
Freshman
modified on Sunday, June 22, 2008 6:54 PM
|
|
|
|
|
OK, i finally got it. IE expects Files (which we already knew right?). After a little investigation it turns out the a FileDrop is just an array of strings (usualy with just one string in, go figure).
So, simple enough:
void TreeView1ItemDrag(object sender, ItemDragEventArgs e)
{
string[] stuff = new string[1];
stuff[0] = @"http://www.google.co.uk";
.
DataObject data = new DataObject(DataFormats.FileDrop, stuff);
.
this.treeView1.DoDragDrop(data, DragDropEffects.Copy);
}
So, IE will get this info, check the array of strings for the file to open, find your web address, and open it.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Well figured out SK Genius. This could be a useful find
Dave
|
|
|
|
|
Hello,
I am presently creating a list box control for our custom gui application using C# .
The dll is compiled using 1.1 compact framework SDK and is run on windows XP/CE embedded..
The new list box control has to be modified to use custom graphics.. the requirement right now is to replace the windows standard scroll box with the custom images provided..however since we are using compact SDK many of the properties related to the scroll box are not available. Does anyone have an idea a work around .
Regards
Vivian Neil Fernandes
|
|
|
|