|
I have played with generics and I have one question.
Take this simple sample:
<code>
using System;
using System.Collections.Generic;
using System.Text;
namespace FunnyTests
{
public class Funny<T>
{
private T _value;
public T Value
{
get { return _value;}
set { _value = value;}
}
}
class Program
{
static void Main(string[] args)
{
Funny<int> someInt = new Funny<int>();
someInt.Value = 10;
Funny<string> someString = new Funny<string>();
someString.Value = "Test";
// *************************************************
// List<Funny> myFunnyList = new List<Funny>();
// *************************************************
List<Funny<int>> myFunnyIntList = new List<Funny<int>>();
List<Funny<string>> myFunnyStringList = new List<Funny<string>>();
}
}
}
</code>
Well, I wish one List of Funny objects (independent of T is string, integer, etc.), but with the code above I can't. The commented code is what I wish, and the another 2 is what I can do.
Resuming: I can have only lists of (by example) <code>Funny<int></code> objects or <code>Funny<string></code> objects, but not "Funny" objects...
Someone have sugestions?
Thanks for all
-- modified at 23:09 Tuesday 13th December, 2005
|
|
|
|
|
A generic object is in fact a class factory. Funny<string> and Funny<int> are two different classes. Therefore, the only way to do this is with a collection of objects, or if you create a new class heirarchy, where each derived class contains a Funny with a different template argument.
But if you do that, the code to get at those objects will be pretty ugly.
Christian Graus - Microsoft MVP - C++
-- modified at 23:15 Tuesday 13th December, 2005
|
|
|
|
|
|
Hi folks,
I have just started trying to do some basic graphics using the Graphics Class. I found an excellent tutorial on CodeProject about making a scrolling window with graphics in it and implemented it with no problems within my code. I then wanted to add a Scaling Function using the PageScale feature, but now the scrolling stops working reliably and I get a jagged pictures with parts printed all over the screen.
I've written a short piece of code to show this problem - if you make the pagescale value 1.0F then everything works fine, any other values result in a mess...
Thanks for any advice...
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace scrollfailure<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.ComponentModel.Container components = null;<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{if (components != null) { components.Dispose(); }<br />
}base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.AutoScroll = true;<br />
this.AutoScrollMinSize = new System.Drawing.Size(600, 600);<br />
this.ClientSize = new System.Drawing.Size(275, 249);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);<br />
}<br />
#endregion<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
private Point rectangleTopLeft = new Point(45, 45);<br />
private Size rectangleSize = new Size(200,200);<br />
private Point ellipseTopLeft = new Point(50, 200);<br />
private Size ellipseSize = new Size(200, 150);<br />
private Pen bluePen = new Pen(Color.Blue, 1);<br />
private Pen redPen = new Pen(Color.Red, 1);<br />
<br />
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
{<br />
<br />
Graphics dc = e.Graphics;<br />
dc.PageScale = 2.0F;
Size ScrollOffset = new Size(this.AutoScrollPosition);<br />
<br />
Rectangle RectangleArea = new Rectangle<br />
(rectangleTopLeft+ScrollOffset, rectangleSize);<br />
Rectangle EllipseArea = new Rectangle<br />
(ellipseTopLeft+ScrollOffset, ellipseSize);<br />
dc.DrawRectangle(bluePen, RectangleArea);<br />
dc.DrawEllipse(redPen, EllipseArea);<br />
<br />
}<br />
}<br />
}<br />
<br />
|
|
|
|
|
Hello I am new to C# and am having a heck of a time making a program work. I am accessing an Oracle database and want to run a query that compares a local variable to the results of the query. I also would like to pass in a local variable in the SQL statement. Is this possible? Here is my SQL statement...
SELECT t.store `store`, MAX(t.tax_rate) `tax` FROM finapps.tax_rate_main t WHERE t.store = " + storeNum + "GROUP BYstore"
The variable "storeNum" is a string and I would like to compare it to the results of the store column and only return 1 value.
I created a windows form application and when the user enters in a store number it compares it to a list of stores in the database with a corresponding tax rate. I want to return the tax rate...
Please help!
Apoc
|
|
|
|
|
apoc503 wrote: SELECT t.store `store`, MAX(t.tax_rate) `tax` FROM finapps.tax_rate_main t WHERE t.store = " + storeNum + "GROUP BYstore"
If storeNum is a string ( I assume it's not, in the database I mean ), you need to put quotes around it. Either way, you need a space before 'GROUP' and after BY, surely ?
Are you having trouble connecting to ORacle at all ? If so, a google of 'Oracle C#' will give you heaps of examples.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I finally got it to work.
conn.Open();<br />
OracleCommand cmd = new OracleCommand();<br />
cmd.Connection = conn;<br />
cmd.CommandText = "SELECT MAX(tax_rate) tax FROM finapps.tax_rate_main t WHERE store = '" + storeNum + "'" ;<br />
cmd.CommandType = CommandType.Text;<br />
<br />
OracleDataReader dr = cmd.ExecuteReader();<br />
dr.Read();<br />
<br />
getTax = Convert.ToString(dr.GetOracleNumber(0));<br />
taxRate = Convert.ToDecimal(getTax);
Oracle was a good place to look...Thanks..
Apoc
|
|
|
|
|
hello,
i a new to C# and i am trying to figure it out! In C++ when adding a class to communicate with a db u add a class and select ODBC Consumer....
How do u add a class like above for C#? Can someone walk me through the steps in vs .net 2003?
thanks,
Lino
|
|
|
|
|
In C++, you were able to use a base class to write a class that was tied to a database. In C#, it does not work that way. A google of 'oledb C#' got me a lot of hits that looked useful, including this[^]
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
I am using a dataview to filter a dataset.
At first the datagrid is populated with 9 records. This is without a filter.
Then I check a checkbox to filter the dataset. This then returns 1 record in the datagrid.
Then I uncheck the checkbox and really I want the datagrid to be populated with the initial 9 records but it only populates with just the one as if the filter checkbox is checked. But the count on the dataset at this stage returns 9 and not 1.
if a dataset is filtered, then how do I get the initial number of records in the dataset (i.e. prior to filtering)?
Any thoughts please?
Thanks
|
|
|
|
|
-Populate Datagrid: Did you restore dataview's Property 'RowFilter' to the value before filtering when you uncheck the CheckBox.
I think you should implement something like this: DataView.RowFilter=CheckBox.Checked? [Your Filter Expression]:[The original RowFilter Expression(normally empty string)];
in the CheckChanged EventHandle;
-Number of Records: did you mean Dataset.Tables[index].Rows.Count .It's independent of on RowFilter property. This number won't change until you Remove a Record from table (Not even Delete) by using Rows.Remove(),Rows.RemoveAt()...functions
|
|
|
|
|
Hi,
Im a new guy in C# dev. I need to develop a component The requirement is..
I will be fetching a recordset from database which is of type dataset.(no problem for me here)
I will be taking the datatable out of the dataset which is having four coloumns..ie OrderID,OrderDate,ItemName,ItemID.
The requirement is to generate a XML file for each OrderID in the datatable.
One OrderID may be associated with Multiple ItemID and ItemName...
I need to filter out the table so the i take One OrderID and associated coloumns(orderdate,ItemID,ItemName) and send those values to other method cof generating the XML string.
Here im having some trouble , How to filter out and from the child table which is having One orderID and other values?..
Table:
OrderID OrderDate ItemName ItemID
1 date itemname1 3
2 date itemname2 4
4 date itemName3 4
1 date itemName2 5
....
I need to generate XML file which will contain information about ONE orderID, and the other details. How to filter and call the xmlgenerate method having only details about one OrderID and associated values.
Happy coding!!
kotteeswaran
|
|
|
|
|
I've tried googling and searching this site on stuff on VSTO in VS2005 and Office2003, but I've come up with very little and was hoping to find either a point in the right direction, or some help. I have an array of strings that is the name of a set of columns, and a table of data that is generated through a call to a SQL server. A listobject limits the functionality of what I want to do, so (at the moment) I'm just manually assigning all the data cell by cell.
Anywho, what I want to do is have the header of each column be a hyperlink, and (its not decided yet) either spawn a new sheet with some information(based on another query), or spawn a new window with the same query. What I need to do is find examples of Hyperlink.Add that lets me either attach the hyperlink to a method, or how to cause the hyperlink to open another sheet/window. At the moment, I'm just simply manually setting the column header text, which are not hyperlinks.
I looked at the MSDN pages as well, and there aren't any concrete examples of what I'm looking for, and in my tinkering I haven't found anything that works yet.
Anyways, a point in the right direction would be greatly appreciated.
-- modified at 16:38 Tuesday 13th December, 2005
|
|
|
|
|
Hi guys :
which are the differences between ServicedComponent(com+) and ClassLibrary(component)?
are they incompatible??????
thanks
-- modified at 15:50 Tuesday 13th December, 2005
|
|
|
|
|
Hi All! I want to write a program that can raise mouse click event( in other window or desktop), but i don't know how to raise that event.
Any Idea??
|
|
|
|
|
Can you rephrase the question please?
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hi there,
You can use SendMessage API...
it should be something like SendMessage(iHandle, WM_LBUTTONDOWN, 0, lparm);
<< >>
|
|
|
|
|
You need to investigate SendMessage and PostMessage. Then, you need to understand the constants WM_LBUTTONDOWN and WM_LBUTTONUP. Then, read Test Run: Low-Level UI Test Automation and you will know everything that you need to accomplish what you want to do.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi!
To send windows a mouse event, you can use the "mouse_event" API of the user32.dll. Decalre as following:
<br />
[DllImport("user32.dll")]<br />
private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);<br />
Here are some constants needed, saved in an enumeration:
<br />
private enum MouseEventTFlags<br />
{<br />
LEFTDOWN = 0x00000002,<br />
LEFTUP = 0x00000004,<br />
MIDDLEDOWN = 0x00000020,<br />
MIDDLEUP = 0x00000040,<br />
MOVE = 0x00000001,<br />
ABSOLUTE = 0x00008000,<br />
RIGHTDOWN = 0x00000008,<br />
RIGHTUP = 0x00000010<br />
}<br />
Now, you can call it like this:
<br />
mouse_event((uint)MouseEventTFlags.LEFTDOWN, 0, 0, 0, 0);<br />
mouse_event((uint)MouseEventTFlags.LEFTUP , 0, 0, 0, 0);<br />
When you send the press-button-down-event, you need to send the press-button-up-event too!
Marcel Erz
|
|
|
|
|
Thanks for your great help, i can raise some event, i'll have to find out how to use it effectively.
|
|
|
|
|
Hi,
Is there any easy way to say that, on textboxHover , if the text inside the box isn't completely visible, to have a popup tool come up showing the complete contents of the box? I'm guessing I need to know if there's a way to determine the number of pixels that some generic text takes up. As an added bonus, is there a way to extract the pixel length from textbox.Size (to save some time looking values up)?
Thanks so much!!!
Mel
|
|
|
|
|
You can use the TextBox.CreateGraphics() method to get a Graphics object. Then, use Graphics.MeasureString() to get the size of the text in the textbox. Then, compare that to the width of the TextBox .
Also, you can use TextBox.Width to determine the number of pixels in the width TextBox .
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
|
No problem! Glad I could help. Happy coding!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|