|
This appeared to work for me, and I think it's what you want, using reflection. Note the Main method and GetValueFromString method. (Sorry for the formatting)
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
static void Main(string [] args)
{
NoddyProcess p = new NoddyProcess();
object o = p.GetValueFromString("foo");
Console.WriteLine(o.ToString());
o = p.GetValueFromString("bar");
Console.WriteLine(o.ToString());
Console.Read();
}
}
class NoddyClass
{
public string foo;
public string bar;
}
class NoddyProcess
{
private NoddyClass nc;
public NoddyProcess()
{
this.nc = new NoddyClass();
this.nc.foo = "thingys";
this.nc.bar = "doodars";
}
public object GetValueFromString(string value)
{
FieldInfo info = nc.GetType().GetField(value,BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public );
return info.GetValue(nc);
}
}
class AnotherNoddyProcess
{
private void DoSomething()
{
NoddyProcess np = new NoddyProcess();
np.GetValueFromString("foo");
}
}
}
|
|
|
|
|
I want to display image in DataList.Path of image is saved in a table of databse Sql Server 2000.Someone help me , please.
nothing
|
|
|
|
|
How to create a link in a Excel worksheet to refer a local worksheet in the same workbook using Microsoft.Office.Interop.Excel . The link should not be absolute it should be relative so that the sheet can work properly if viewed in another machine .This should work much similar like a table of contents in a Word Document
Karthekeyan
|
|
|
|
|
First you have know exactly what you want to do in Excel terms so, "should work much similar like", is not sufficient.
Next to do this from C# you would use the Excel Object Model which is available through the Primary Interop Assembly which you can down load from Microsoft. The Excel Object Model is documented on MSDN.
|
|
|
|
|
I'd recommend start recording a Macro in Excel, perform the task you want, then stop recording. Then edit the macro to see what VBA code was generated. This will give you an idea of what to do. In this case, Excel generate the following code:
Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"Sheet2!A1", TextToDisplay:="This is a test"
The object model should be idential in the .Net API. See this[^] for documentation on the Hyperlinks.Add method.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi Tom,
Thanks very much for the tip off i was able to link sheets using hyper link now and its even relative not absolute. Below is the code to generate a relative hyperlink using C# through Microsoft.Office.Interop.Excel
Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Excel.Workbook workbook = xla.Workbooks.Add(Excel.XlSheetType.xlWorksheet);
Excel.Worksheet worksheet = (Excel.Worksheet)workbook.ActiveSheet;
Excel.Worksheet worksheet1 = (Excel.Worksheet)workbook.ActiveSheet;
worksheet.Hyperlinks.Add(worksheet.Cells[1,1],"","Sheet2!A1","Test","TestMe");
xla.Visible = true;
Regards,
karthekeyan.
|
|
|
|
|
Hi Friends,
I have a requirement to add new rows to the DataGridView UI which is bound to a DataTable.
The new row added to the UI should get added to the underlying DataSource.
I have bound the DataGridView to a DataSource.
The DataSource consists of 10 columns out of which only 5 columns were bound to the DataGridView.
The other 5 columns which are not bound consists of composite primary key on 2 columns and 3 other columns will not accept null values.
I have tried with "DefaultValueNeede" event of the DataGridView to define the default values for the new row.
As only 5 columns are bound to the DataGridView, I could supply the default values only to those columns.
How would I supply the default values to the rest of the columns which are not bound to the DataGridView?
Which event of the DataGridView should be handled in this scenario?
An exception is thrown when I tried to commit the new row in the DataGridView UI (by adding a "new new row") to the DataGrid.
The exception is that "Required values are not supplied to the new DataRow" which are the composite primary key columns (2) and not null columns (3).
Thanks.
Subrahmanyam K
|
|
|
|
|
Subrahmanyam K wrote: I have tried with "DefaultValueNeede" event of the DataGridView
Why? Are you following some book, article or tutorial? If not CodeProject very likely has one or more articles that cover this topic.
|
|
|
|
|
I turn on timer in C#,I known we can use timer.enable b=false to turn off timer but when I close application I don't can call timer.enable=false because of many causes,can I use other command
help me
|
|
|
|
|
I don't understand your question. timer.Stop() will stop the timer???
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Its odd, all timer.Start() and timer.Stop() seem to do, is set the enabled property to true or false. I suppose it saves a few key strokes though.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
:(I have form1.aspx and code behind for this form (form1.aspx.cs). I have a UserControl (UserControl1.cs) that is built in a package dll that is included in the project. The DLL has been added as a reference.
What I am trying to do is access UserControl1's Set() method from within my code behind (form1.aspx.cs).
Here is an example of the set method in UserControl1.cs. FYI, I am not using the get() method at this time.
public string psField1
{
get { return __Field1; }
set { _Field1 = value; }
}
So, in form1's code behind, I assume I will have to instantiate UserControl1.cs first.
PackageControl.UserControl2.......
now I need the rest to access the set() method in UserControl1.cs to set
|
|
|
|
|
If the user control is in use on the page, then it should just be
myControl.psField1 = x;
if you don't have an instance of the control on the page, then why would you want to access the set method ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi guys,
i want to save and retieve images into sql server 2005. i have a table caled resourcephotos with the columns:
res_id(int) and res_photo(image).
i don't have problems with saving the images into the database...when a new image is saved, then u see in the res_photo column <binary data="">
bud when i want to select the image and set it to the picturebox i get the error: parameter is not valid
here some code of my app to retrieve image and set it into the picturebox:
SqlCommand cmd27 = new SqlCommand("SELECT Res_photo FROM ResourcePhotos WHERE Res_id = '" + res_id + "'", myconn);
byte[] b = (byte[])cmd27.ExecuteScalar();
MemoryStream myms = new MemoryStream(b);
Image img = _res.pictureBox1.Image;
img = Image.FromStream(myms); <--------------HERE has the error to do
_res.pictureBox1.Image = img;
i also tried Bitmap instead of Image, bud i got the same error.
does anyone any idea? thanx.
|
|
|
|
|
Djavid j wrote: <--------------HERE has the error to do
What error? You don't think we need to see the error message to help?
Do you know what the result of your SQL command is?
|
|
|
|
|
u can read the error clearly in my post...bud here again: the parameter is not valid
|
|
|
|
|
Djavid j wrote: u can read the error clearly in my post
My bad, I missed it.
That indicates that the data parameter you are giving to Image.FromStream() is not valid image data. I cannot determine why as there could be many reasons, here are a few:
The data is not stored in the database correctly
The query did not return a result
The code is not dealing with the query result correctly (casting it to a byte[]).
|
|
|
|
|
it's okay, thanx for the quick response.
i don't know wheater the image data is correctly saved, cause i see in the column res_photo only this: <binary data=""> . bud i know for sure that other data is correctly saved and the query returns also a result, i tested by resturning the res_id by a messagebox.
and whether the code is not dealing with the query result, i have no idea.
|
|
|
|
|
I think using ExecuteScalar() might be the problem, a byte[] might not be supported.
|
|
|
|
|
|
Hi, sorry if I have missed or not read all of your Tab Articles, but I never see a example of maybe doing the paste/copy command when a user is allowed to create their own tabs with text boxes in them. Since they are in a array under the name of newRtb it gets confusing how to allow the user to lets say paste information on a selected tab with a Rich Text Box in it.
Any suggestions on what to do? I do have code, but it does not work...
private void Cut(object sender, System.EventArgs e)
{
int index = this.Controls.IndexOfKey("newRtb");
if (index != -1)
{
Control control = this.Controls[index];
RichTextBox richTextBox = control as RichTextBox;
if (richTextBox != null)
{
richTextBox.Cut();
}
}
}
I am completely lost on how to do this and this is the only thing stopping me from finishing my program I made.
Thanks, Ajm113
-- modified at 12:04 Wednesday 10th October, 2007
|
|
|
|
|
Hi!
When I try to serialize a object that has a TimeSpan property that property is serialized as if it is null even if it was set.
Can anyone help me?
Thanks,
Lukas
|
|
|
|
|
Are you using the XmlSerializer? If so, then check this[^] out.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
|
See my reply to that thread.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|