|
You can use a RadioButtonList and add the items in the serverside code, you can also use its datasource property and dtabound method to bind the list from the database, or just use Items.Add if you want to hardcode the list.
<edit> sorry i assumed that you were using asp.net fogot i changed forums. there my be a similar control in winforms i cant remember, or you might be able to add them to the forms or panels control collection, but positioning them correctly would be difficult, it may be easier to have a fixed number and just show or hide them.
modified on Monday, May 19, 2008 8:56 AM
|
|
|
|
|
thanks for answering ,
but I did not find such control in windows form
and I need the number of the radio to be for example from the user , so I should create as many as the user needs
when I tryed to use Controls.Add of the panel , it added only one radio button,
should I change some of the properties of the panel ?
Thanks
There is always something to learn
|
|
|
|
|
each time you call Add it will only add one button you'd have to use a loop to add multiple, but then finding them in the form to do something with becomes slightly difficult but not impossible. or if you knew the maximum number of controls you could have them already there but just invisible then go through and make them visible for each case. I'm not sure how well the layout will work if you add them via a loop and the Controls.Add method, and you have the possibility of adding controls that the user cant see or interact with.
|
|
|
|
|
mmmmm, thanks for replying
the fact is: there is no max number of those radio buttons ,
also I am already using loop , but still I only see the first radio button in the run instead of all of them
any other ideas!
thanks again
There is always something to learn
|
|
|
|
|
If there's no max number, then you'll have to resize the form to fit all of the controls.. However Have you tried creating a new control in the code i.e. RadioButton rb = new Radiobutton(); then setting its x,y coordinates to something, they may be defaulting to 0,0 and just appearing on top of each other. you'll have to use those settings to make sure that they are all visible to the user and visible so that they can be clicked on. Also if you do this after the form has been shown they user may notice a delay and/or see the controls appearing and the form resizing, which isnt the best in terms of UI, some users may freak out a little bit.
|
|
|
|
|
that was very helpful,
Thaaanks a lot
There is always something to learn
|
|
|
|
|
You're welcome and thanks for ranking my replies. helps me know how good my answers are.
|
|
|
|
|
Hey guys...
i need so send a couple of parameters to a crystal report...
does anyone know any good articles on the subject?
thanX
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
|
Hi there,
After reading msdn, looking for answers in google and testing a lot of different things, I gave up and now I'm here hoping for an answer.
The Problem:
I'm having a big problem trying to delete a row from a DataTable wich is related to its father. The exception I'm receiving is "Null Reference exception" (or something like that, my visual studio isn't in english)
The structure:
DataSet dsData contains:
DataTable dtbClients -> PrimaryKey: 'MotherAccount'
DataTable dtbAccounts -> PrimaryKey: 'ClientName'
DataTable dtbProducts -> PrimaryKey: 'CodeProduct'
Wich are related like this:
dtbClientes -> dtbAccounts (through column 'MotherAccount')
dtbAccounts -> dtbProducts (through column 'ClientName')
The data:
In this specific case, dtbClients has only 1 client wich has 1 account (in dtbAccounts) with no products.
What am I tried to do:
First I tried to remove the client directly because I though that the cascade constraint automatically created when we make a relation would take care of deleting the associated row in dtbAccounts. But that didn't happend.
The application threw and Null Referenec exception, and the stackTrace pointed to a function with 'Cascade' in its name.
Question 1): Is it possible to fix this exception and make c# delete everything associated to the removed client?
Well, with this exception I quited trying to delete the client directly and tried something else.
This time I'm removing the account related to the client first, this way when deleting the client there would be no problems since there are no rows related to it (I've no problems deleting clients with no accounts associated).
The problem:
It gives me the same Null Reference exception when trying to delete the account first! And it doesn't have any product related to it. My guess is that somehow the parent row(client) is related to it, so I can't delete it.
Question 2): How do I delete this account?
Can anyone help me with this ?
I hope I was clear enough.
Oh, another thing,
What I'm trying to do over there is actually one part of a mergin process of 2 datatables.
Actually is not a merge, it is an update.
The old dataset will be updated to look exactly like the new one, wich means that new rows will be added, old rows will be updated and old rows will be removed.
Well, I've just discovered the DataSet.Merge(DataSet) function and it is quite usefull.
The problem is that it doesn't seem to remove old rows in the target dataset that are not in the (updated version) source dataset.
Is there a way to do this not manually? A function? A property? I don't know... something that would make the Merge function delete rows from the target dataset.
Thanks in advance!
Oscar
|
|
|
|
|
Hello,
I'm trying to read messages from an outside source that orks on 30HZ (every 33 msec there is a new message).
I tried to use the udp classes in .Net but I discovered that althogh 80% of the time the messages reciveing interval is about 33 msec, sometimes i get picks of 50 and more.
1. How would you solve it ?
2. Is it beacuse it is a UDP connection ?
3. Can I recieve in a diffrent way (using dllimport to some udp recieving dll for example ?).
thanks,
|
|
|
|
|
You're using an inaccurate clock. The Windows tick timer (Environment.TickCount ) ticks at a frequency of around 15-16ms, so you will normally see durations measured with this timer as being some multiple of 16ms. Try using the Stopwatch class instead, if using .NET 2.0 or later.
That said, UDP is always susceptible to network delays. Routers can delay or drop packets if a link is saturated. LANs will drop packets and have to retransmit if two stations try to send at the same time (this is referred to as a collision). You would need a dedicated link to avoid the possibility of a collision.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
nope, i'm using the multimedia timer, which is just as accurate as the Stopwatch.
|
|
|
|
|
Hello everyone,
Here is my code to make a duplicate value copy of all the Values in a dictionary instance -- not just reference. So, I use CopyTo method.
My current issue is, I think my code is stupid but do not know how to solve it. My specific concern is,
1.
the code Foo[] FooArray = new Foo[3] creates 3 new instances of Foo, the code dic.Values.CopyTo(FooArray, 0) will overwrite the 3 new instances of Foo? So, seems it is stupid to create 3 new instances of Foo in Foo[] FooArray = new Foo[3], but never use them and overwrite them? Any ideas? Is it an issue?
2.
Maybe I am wrong, the code Foo[] FooArray = new Foo[3] creates only references variable of Foo class? Not class instances variable themselves?
class Foo
{
public int abc;
public Foo (int i)
{
abc = i;
}
}
public static void Main()
{
Dictionary<int, Foo> dic = new Dictionary<int,Foo>();
dic.Add(1, new Foo(10));
dic.Add(1, new Foo(20));
dic.Add(3, new Foo(30));
Foo[] FooArray = new Foo[3];
dic.Values.CopyTo(FooArray, 0);
return;
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: the code Foo[] FooArray = new Foo[3] creates 3 new instances of Foo
Buzz! Wrong!
It allocates an array with 3 spaces for Foo. It does not instantiate any Foo instances, only an instance of Array . Dont believe me? Try accessing one of them:
Foo[] FooArray = new Foo[3];
Console.WriteLine(FooArray[0].abc.ToString());
|
|
|
|
|
Thanks J4amieC!
So this code Foo[] FooArray = new Foo[3] will only create 3 references and make them refer to NULL? Then code dic.Values.CopyTo(FooArray, 0) will create 3 instances of Foo class, and assign the 3 NULL references variables in FooArray to point to the instances?
regards,
George
|
|
|
|
|
George_George wrote: So this code Foo[] FooArray = new Foo[3] will only create 3 references and make them refer to NULL
Exactly
George_George wrote: hen code dic.Values.CopyTo(FooArray, 0) will create 3 instances of Foo class
No, you're doing that above with lines like
dict.Add(1,new Foo(10))
You're then copying references to these into the array. Each Foo is only created once.
|
|
|
|
|
Thanks J4amieC!
1.
I am confused why do you think the code "dic.Values.CopyTo(FooArray, 0)" is the same as the code "dict.Add(1,new Foo(10))"? I think code "dic.Values.CopyTo(FooArray, 0)" will fill array FooArray, and "dict.Add(1,new Foo(10))" will fill dic dictionary instance. They are of different types.
Why do you think they are of the same effect?
2.
"code dic.Values.CopyTo(FooArray, 0) will create 3 instances of Foo class" -- what is wrong? I think not the reference, but the real new copy is created?
regards,
George
|
|
|
|
|
George_George wrote: I am confused why do you think the code "dic.Values.CopyTo(FooArray, 0)" is the same as the code "dict.Add(1,new Foo(10))"
I never said that. Lets go back a bit. You said:
"Then code dic.Values.CopyTo(FooArray, 0) will create 3 instances of Foo class"
and I said that this was not the case, that the code in the lines above are what actuall instantiated the Foo instance, not the act of using the CopyTo method.
George_George wrote: I think not the reference, but the real new copy is created?
Im 99% sure you're copying the references not making a new instance.
|
|
|
|
|
Thanks J4amieC!
1.
"that the code in the lines above are what actuall instantiated the Foo instance" -- sorry my English is not good. And I am confused about, "the code in the lines above" -- which code do you mean? Could you list here please?
2.
J4amieC wrote: Im 99% sure you're copying the references not making a new instance.
I think you are correct. I have written code to verify. Could you help to review whether my code is correct to test only reference, not instance value themselves are copied please?
class Foo
{
public int abc;
public Foo (int i)
{
abc = i;
}
}
public static void Main()
{
Dictionary<int, Foo> dic = new Dictionary<int,Foo>();
dic.Add(1, new Foo(10));
dic.Add(2, new Foo(20));
dic.Add(3, new Foo(30));
Foo[] FooArray = new Foo[3];
dic.Values.CopyTo(FooArray, 0);
FooArray[0].abc = 40;
Console.WriteLine(dic[1].abc);
return;
}
thanks in advance,
George
|
|
|
|
|
Yeah, the code is fine for the test.
|
|
|
|
|
|
A new object is only instantiated when it is contructed with 'new' else they are references.
|
|
|
|
|
Thanks leppie,
I think CopyTo will create new instances, other than just make a copy of the reference, right?
regards,
George
|
|
|
|
|
George_George wrote: I think CopyTo will create new instances, other than just make a copy of the reference, right?
Buzz! Wrong Again!
Here's a little test app to convince you:
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
namespace ConsoleApplication2
{
class Foo
{
public int abc;
public Foo(int abc)
{
this.abc = abc;
}
}
class Program
{
static void Main(string[] args)
{
Dictionary<int, foo=""> d = new Dictionary<int, foo="">();
d.Add(1, new Foo(10));
d.Add(2, new Foo(20));
d.Add(3, new Foo(30));
Foo[] fooArray = new Foo[3];
d.Values.CopyTo(fooArray, 0);
Console.WriteLine(d[1].abc);
Console.WriteLine(fooArray[0].abc);
Console.WriteLine("Same Instance? {0}", (d[1] == fooArray[0]));
Console.ReadLine();
}
}
}
</int,></int,>
Output:
10
10
Same Instance? True
This implies that I have picked the Foo instances with the same abc value (one from the dictionary one from the array), and when I check the for equality (which checks the reference not the value of abc it comes out true.
|
|
|
|
|