|
First, welcome as a new member to CP. This would be better to be asked in the Visual C++[^] forum since you are asking for C code. This forum is for C# questions.
Steve Maier, MCSD MCAD
|
|
|
|
|
Thanks... I am moving it over.
|
|
|
|
|
Logic is same whether it is c or C#. here i am writing example using C#. Try to use correct syntax in c for printing and reciving variable in c while using this logic.
using System;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
int n=5;
for(int i=0;i < n;i++)
{
Console.Write(" *");
} Console.Write("\n");
}
}
}
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Do we have to smack you? Make suggstions and point her in the right direction! Don't write the code for her! How is she going to learn anything if your doing her work for her?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi all
I realise this is probably the most basic C# question I could ask, so apologies in advance, but I have searched everywhere and just can't seem to find a complete answer, all in one place.
I have a class called Donor. Inside Donor, I have properties such as Name, Address, Telephone, etc, but I would also like a collection of Donation classes.
The Donation class has properties such as Date, Amount, MethodOfPayment, etc.
So, I have a Donor class and a Donation class. And I would like my Donor class to contain a collection of Donation classes, which can be added to, removed from, and iterated around using foreach.
Could someone show me the basic steps I need to go through in order to achieve this, or point me in the direction of a good example that encompasses this problem.
Many thanks
M
|
|
|
|
|
isittheweekendyet wrote:
Could someone show me the basic steps I need to go through in order to achieve this, or point me in the direction of a good example that encompasses this problem.
You might consider having you Donation class inherit from CollectionBase which is an abstract base class for a strongly typed collection. There is a perfect example on MSDN located here[^]. If you have further questions please feel free to ask.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Here you are trying to create collection of your own type. That is cool. But before starting this, Please go through this article, which discuss clearly about custom collection and iteration. I recommand you to read this for better understanding of custom collection.
Handling Custom Collection
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Hi all, I am trying to pass a function name as a parameter and use it to create an OracleDataReader:
<br />
private void DataHandler(string type, string function)<br />
{<br />
AuthViewsLookup myLookup = new AuthViewsLookup(m_AppParam);<br />
<br />
OracleDataReader rdr = myLookup.function;<br />
<br />
while(rdr.Read())<br />
{<br />
}<br />
<br />
rdr.Close();<br />
}<br />
setting the reader to myLookup.function does not work, b/c it wants the actual function name. How can I make this work? Thanks for any help.
|
|
|
|
|
|
That's not exactly what I meant. I want to tell it what function to go to by passing in the function's name.
|
|
|
|
|
I’m a fairly new programmer (was taught C++ over a two year program NAIT) and very new to C# and I was hoping someone can explain to me why string doesn’t have a constructor that accepts a string? To me the following line of code seems intuitively correct but it doesn’t work.
string s = new string(“dog”);
or
string s = new string();
s=”dog”
There must be a reason that the above doesn’t work (other than making me angry.)
The closest I can come to doing the above is
string s = “dog”;
or
string s = “\0”;
And that works but I’d like s to be DMAed.
Admittedly, my understanding of DMA with managed code is week at best. That may be the problem. Any explanations will be helpful.
Thank you,
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
12029 45 Street N.W.
Edmonton, Alberta, Canada T5W 2T7
Res. Ph: (780) 695.5589
Email: rhahn82@telus.net
|
|
|
|
|
I'm not entirely sure why this really matters to you, however if you look through the documentation you will see there are a series of different parameters that the String class can take as a parameter for its constructor. You could do the following (if you wanted that is):
string s = new string("Hello".ToCharArray());
The string class is a reference type, so remember it's important to check for a null value, but otherwise just use the assignment operator, which is how the majority of people tend to use it.
string s = "Hello";
- Nick Parker My Blog | My Articles
|
|
|
|
|
So because it’s a reference type trying to put it on the heap is redundant? Why doesn’t anyone do this:
string s = new string("Hello".ToCharArray());
?
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
HahnTech wrote:
So because it’s a reference type trying to put it on the heap is redundant?
No, your missing the point, I am just not sure I understand why you are hung up on the design of the class? Like I said, what I showed you is simply something you could do, however unlikely.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I am so frustrating to make list in propertygrid by using arraylist. I am well-aware about other articles about this, but I cant get it working. Do I have to use PropertyDescriptorCollection or ICollection? I am not sure bec I dont know which is best to use for building list in propertygrid by arraylist.
I want nodes to look like this:
For example:
-Category
-List 1
Color
Length
....
+List 2
Color
Length
....
+List 3
....
|
|
|
|
|
If you want your collection of properties "rolled-out" (i.e., no "..." button) in the PropertyGrid then your object will need to implement ICustomTypeDescriptor and override the two GetProperties methods. For everything else, just return TypeDescriptor.AppropriateMethod with noCustomTypeDesc parameter set to true (so that it doesn't recursively call your ICustomTypeDescriptor method).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am little confusing about override the two GetProperties methods. Can you give me more specifics about that? I was curious about TypeDescriptor.AppropriateMethod method so I looked at MSDN library and it was not there. How did you find its method?
|
|
|
|
|
Notice how AppropriateMethod was italicized/emphasized? That means it's not actually what you look up. It would've been logical for you to lookup the TypeDescriptor class even if I did mispell a method or property name and look at it's class documentation. For example, look up TypeDescriptor in the .NET Framework SDK documentation and you'll see the GetProperties overloaded methods.
When you implement the ICustomTypeDescriptor you simply define the two overloaded GetProperties methods as you would with any other interface members. If you're confused about how to implement interfaces, then I suggest you first read the C# Language Specification[^], specifically about Interfaces[^].
For example:
public class MyClass : ICustomTypeDescriptor
{
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
}
public PropertyDescriptorCollection GetProperties()
{
return GetProperties(null);
}
public PropertyDescriptorCollection GetProperties(Attribute[] filter)
{
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for telling about this:read the C# Language Specification[^], specifically about Interfaces[^]. and it helped me alot but it didnt help me with my current problem. I did what I still trying to get any results from PropertyDescriptorCollection in propertygrid, but all I got is blank. I followed your suggestions and I got it all in collection from arrays.
public class CMainForm : System.Windows.Forms.Form
{
public void ShowPropertyGrid()//init. propertygrid with datas and objects
{
ArrayList arrayList = .....///stored the arraylist from other class
foreach(ILogical pILogical in arrayList
{
string[] strHeaderArray = null;
((IEVHeaderItem)pILogical).GetHeaderDetails(out strHeaderArray);
SubListInfo.Lists.List = "List" + nCount;);///List1, List2, List3,....
SubListInfo.Lists.Type = pILogical.Type;
for(int i=0; i < strHeaderArray.Length; i++)
{
string strValue;
((IEVHeaderItem)pILogical).GetDetailColumn(i, out strValue);
if(i == 3)
ListInfo.Lists.Color = strValue;
........
}
}
}
}
[TypeConverter(typeof(SurfaceConverter))]
public class SubListInfo : SubListData
{
private int m_nID = 0;
private string m_strColor = "";
.......
public SubListInfo()
{
}
[ReadOnly(true)]
public string Color
{
get { return m_strColor; }
set { m_strColor = value; }
}
..........
}
public class SubListData
{
private string m_strList = "";
......
public SubListData() {}
[Browsable(false)]
public string List
{
get { return m_strList; }
set { m_strList = value; }
}
....
}
public class CListInfo : ICustomTypeDescriptor
{
private ArrayList m_arrayList;
#region ICUSTOMTYPEDESCRIPTOR
public String GetClassName()
{
return TypeDescriptor.GetClassName(this,true);
}
... I followed those rest of them like you said from previous message.
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public PropertyDescriptorCollection GetProperties()
{ return GetProperties(null); }
[TypeConverter(typeof(ListConverter))]
public PropertyDescriptorCollection GetProperties()
{
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
for(int i = 0; i < m_data.Count; i++)
{
SurfaceCollectionDesc pd = new SurfaceCollectionDesc(m_data,i);
pds.Add(pd);
}
return pds;
}
#endregion
}
internal class ListConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType )
{
if( destType == typeof(string) && value is SurfaceInfo )
{
ListInfo emp = (ListInfo)value;
return emp.List;///List1, List2, List3,....
}
return base.ConvertTo(context,culture,value,destType);
}
}
I tried to used those codes(below) if its collection(there is three lists for now) is working or not. so it showed only last List(List3) and it didnt displayed first two lists.
[TypeConverter(typeof(ListConverter))]//,CategoryAttribute("Lists")]
public SubListInfo Lists
{
get
{
return subLists;
}
}//////it showed only last List(List3)
Did I miss something important about PropertyDescriptorCollection or TypeConverter
that displays whole lists? I may overlooking something that I alway do that.
|
|
|
|
|
Hello,
I want to use SinatureCapturing (Saving the Signature in Sql Server Ce Database and Retrieving the Signature from Sql Server Ce Databse). from the MSDN Example: http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull=/library/en-us/dnnetcomp/html/PPCSignatureApp.asp
I looked at this example and after one while I came to the realization that I have to use the SignatureControl.cs File and the Network.cs File.(I added this files to my application). Then I add the following code to my Main Form (I know that the database saving requires additional code, but I want only test at the beginning if the Control is displayed and if I am able to write on this Control with the pen.):
SignatureControl _signature = new SignatureControl();
and in the constructor:
_signature.Location = areaSignature.Location; //areSignature is the name of the panel
_signature.Size = areaSignature.Size;
this.tabPage2.Controls.Add(this.areaSignature);
I only added this code to the MainForm according to the constructor and FormLoad Method of the MainForm of the sample application. (I also set the sign here file to embedded resource of my application.)
But when I deploy the application the panel is displayed without any additional functionality or the bachground sign here.
Anybody an idea what I have forgotten?
robert
|
|
|
|
|
|
I want to know how to use DataGridColumnStyle to set the width of my datagrid. I know how to use PreferredColumnWidth to set the width of the oveall colunm, but it is not what I want. I want to set individual column.
Here is my program
I also want to know if there is a good documentation for the .net classes. While I was working in the DataGridClass. My class is defined as dataGrid1, from dataGrid1, there is not way to know that DataGridColumnStyle exists. I want to know is there is a good book or documentation tha point out intaction between associated classes like for instance DataGrid and DataGridColumnStyle.
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
double[] dData1 = new double[100];<br />
double[] dData2 = new double[100];<br />
<br />
DataTable dt = new DataTable();<br />
DataRow dr;<br />
<br />
dt.Columns.Add(new DataColumn("Index", typeof(int)));<br />
dt.Columns.Add(new DataColumn("Sinve Values", typeof(float)));<br />
dt.Columns.Add(new DataColumn("Cosine Values", typeof(float)));<br />
<br />
dataGrid1.PreferredColumnWidth = 100;
<br />
for(int i=0;i<100;i++)<br />
{<br />
dData1[i] = Math.Sin(0.1*i);<br />
dData2[i] = Math.Cos(0.2*i);<br />
dr = dt.NewRow();<br />
dt.Rows.Add(dr);<br />
dr[0] = i;;<br />
dr[1] = dData1[i];<br />
dr[2] = dData2[i]; <br />
} <br />
dataGrid1.DataSource = new DataView(dt); <br />
waveformPlot1.PlotY(dData1);<br />
waveformPlot2.PlotY(dData2);<br />
}<br />
|
|
|
|
|
If you want to know if there's good documentation, then read it and determine whether you think it's good.
You can set the width of a specific column using a DataGridColumnStyle that you add to a DataGridTableStyle for a specific DataTable (or type, if reflecting against something other than a DataSet or DataTable ), which you add to DataGrid.TableStyles .
You should read the documentation, which also presents articles. The DataGridColumnStyle does exactly what you're asking and is specific to the column it represents in a DataGrid .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
After adding all these extra codes, it still doesn't work. It shouldn't take all too much effort jsut to increse or decrease the length of a column in a grid.
In terms of the documentation, I think it would have been bette to show interaction from one class to another.
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
double[] dData1 = new double[100];<br />
double[] dData2 = new double[100];<br />
<br />
DataTable dt = new DataTable();<br />
DataRow dr;<br />
DataGridTableStyle ts1 = new DataGridTableStyle();<br />
DataGridColumnStyle boolCol = new DataGridBoolColumn();<br />
<br />
dt.Columns.Add(new DataColumn("Index", typeof(int)));<br />
dt.Columns.Add(new DataColumn("Sinve Values", typeof(float)));<br />
dt.Columns.Add(new DataColumn("Cosine Values", typeof(float)));<br />
<br />
ts1.MappingName = "Index";<br />
boolCol.MappingName = "Index";<br />
boolCol.Width = 20;<br />
ts1.GridColumnStyles.Add(boolCol); <br />
dataGrid1.TableStyles.Add(ts1);<br />
<br />
for(int i=0;i<100;i++)<br />
{<br />
dData1[i] = Math.Sin(0.1*i);<br />
dData2[i] = Math.Cos(0.2*i);<br />
dr = dt.NewRow();<br />
dt.Rows.Add(dr);<br />
dr[0] = i;;<br />
dr[1] = dData1[i];<br />
dr[2] = dData2[i]; <br />
} <br />
dataGrid1.DataSource = new DataView(dt); <br />
waveformPlot1.PlotY(dData1);<br />
waveformPlot2.PlotY(dData2);<br />
}<br />
|
|
|
|
|
It's not difficult, but your problem is that you need to name your DataTable . The DataGrid associates a particular DataGridTableStyle with a DataGrid by matching the DataTable.TableName (you can pass this to the constructor) with one of the DataGridTableStyle 's MappingName that was added to the DataGrid.TableStyles property. Your modified code below works fine:
double[] dData1 = new double[100];
double[] dData2 = new double[100];
DataTable dt = new DataTable("Test");
DataRow dr;
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = dt.TableName;
DataGridColumnStyle boolCol = new DataGridBoolColumn();
dt.Columns.Add("Index", typeof(int));
dt.Columns.Add("Sinve Values", typeof(float));
dt.Columns.Add("Cosine Values", typeof(float));
boolCol.MappingName = "Index";
boolCol.Width = 20;
ts1.GridColumnStyles.Add(boolCol);
dataGrid1.TableStyles.Add(ts1);
for (int i=0; i<100; i++)
{
dData1[i] = Math.Sin(0.1*i);
dData2[i] = Math.Cos(0.2*i);
dr = dt.NewRow();
dt.Rows.Add(dr);
dr[0] = i;
dr[1] = dData1[i];
dr[2] = dData2[i];
}
dataGrid1.DataSource = dt; You did, however, forget to add column styles for your other columns. When you use table styles with defined columns (even just 1), no columns are auto-generated.
Besides, using a DataTable here is unnecessary. A simple array of some struct like so would work:
public struct Data
{
public int Index;
public double Sinve;
public double Cosine;
} In this case, you set DataGridTableStyle.MappingName to "Data". This is documented in the DataGridTableStyle.MappingName property documentation.
Also, why are you binding a DataGridBooleanColumn to an int DataColumn ? That's going to set it to either 0 or 1 and will start (for all but the first row) in an indeterminate state.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|