|
Hi All,
I have an array of UserRights (class that holds the rights for an individual table) called arrTables and an array of controls called arrControls (10 of each type of control needed). The arrControls are displayed/listed on a Windows form (TableName, ViewRights, EditRights...) so that the data for 10 tables can be viewed at one time. I've bound the data to the form controls using the following code:
for (int iLoop = 0; iLoop < 10; iLoop++)
{
ctrlQAControls[iLoop, 0].DataBindings.Clear();
ctrlQAControls[iLoop, 0].DataBindings.Add(new Binding("Text", arrTables, "TableName"));
currencyMgr.Position++;
}
When I try and display the form to the user data from the 10th table stored in the arrTables array is displayed in all 10 sets of controls. I learnt that the CurrencyManager holds the value of the Current possition and that is the reason for these results.
Is there a way around or an alternative way to implement this without hacing to use a datGridView or other list control?
Thank you
|
|
|
|
|
It sounds as though you should be using a view of the data instead of binding to 10 different datasource all at once.
But since you appear to want 10 seperate data navigations going on at the same time you'd use 10 BindingSource objects, each having its DataSource property set to the table you want it to navigate over, then set each controls DataSource property to the BindingSource it should be using.
|
|
|
|
|
Hi Dave,
Thank you for your reply. I've attempted to follow the steps above only the array of controls doesn't have a DataSource method, so I'm unable to set the DataSource of the controls in the array to a BindingSource. Here is what I have:
BindingSource bs1 = new BindingSource();
bs1.DataSource = arrTables;
ctrlQAControls[0, 0].?!?;
Could you tell me how I would go about assigning each controls DataSource property, in the array to a given BindingSource?
Thank you
|
|
|
|
|
If you want to have 10 separate controls each bound to one of the 10 model objects, then you don't need to bother with a currency manager:
for (int iLoop = 0; iLoop < 10; iLoop++)
{
ctrlQAControls[iLoop, 0].DataBindings.Clear();
ctrlQAControls[iLoop, 0].DataBindings.Add(new Binding("Text", arrTables[iLoop], "TableName"));
}
This does seem like a situation where you should be binding to some sort of list control though.
PS you should ditch the Hungarian type naming when you're writing C# code.
|
|
|
|
|
Hi Dave/Bob,
Thank you both for your feedback. I'm going to try the BindingSource objects recomendation now.
Bob- the method you sujected, does this take into account that there are more than 10 objects that need to be binded to the controls? There will be 10 objects bound at any one time, but then I have next and previous buttons to display the next and previous 10 objects.
Thank you again
|
|
|
|
|
Hi guys,
The question is of pure interest: how do you prefer naming a variable/parameter of type Object ?
Most of the time it depends upon the logic of its usage, but not always. Sometimes you just want to express a generic entity:
public byte[] Encrypt(Object x)
public byte[] Serialize(Object o)
Its tempting to name x as obj or objToEncrypt , but it sounds more like a Hungarian notation.
So how would you consider naming it?
|
|
|
|
|
|
Thanks for suggestion,
I was always tempted to append "to". In that case it would be toEncrypt . But it scratches my ear badly. I really like encrypt but its a verb, and it breaks the convention a little.
As for your CommandDoSomething.DoSomething example. I might have misunderstood you, but I prefer not appending action name to class name or viceversa:
User client = User.Create();
User client = User.CreateUser();
Anyway, I believe its a matter of preference
Regards
|
|
|
|
|
I like to
<pre lang="c#">pub byte[] Encrypt(object aValue)</pre>
where a is for argument
I usually do this for class members
<pre lang="c#">int iVariableName</pre>
<pre lang="c#">string sVariableName</pre>
<pre lang="c#">byte [] byData</pre>
sometimes ill append an 's' to arrays
<pre lang="c#">string [] sNames</pre>
Common .net objects I like to turn to an acronym
FolderBrowserDialog - fbd
SaveFileDialog - sfd
StringBuilder - sb
Socket - soc or cli
The result of a method is usually called result no matter what type.
|
|
|
|
|
The only time I even append a type to an object name is when I'm naming controls. For example, Building_TextBox or Building_ComboBox. It comes in handy if you have a couple of controls related to the same thing.
|
|
|
|
|
public byte[] Encrypt(Object sourceObject)
public byte[] Serialize(Object sourceOject)
..although that would make 'em hard to distinguish from local variables.
public byte[] Encrypt(Object AsourceObject)
public byte[] Serialize(Object AsourceOject)
The prefix stands for "Argument", but "Parameter" would be just as effective
This gives you an assigment statement like
byte[] b = Encrypt(AsourceObject := ObjectThatWouldbeSerialized);
Bastard Programmer from Hell
|
|
|
|
|
Cool stuff, like the sourceObject solution. Though, just source sounds even better.
|
|
|
|
|
Ciumac Sergiu wrote: Its tempting to name x as obj or objToEncrypt , but it sounds more like a Hungarian notation.
So how would you consider naming it?
I would name it 'data'.
|
|
|
|
|
Source, Subject, Value, Victim, etc. ::shrug::
|
|
|
|
|
Message Closed
modified 21-Nov-20 21:01pm.
|
|
|
|
|
|
You should name the parameter in such a way that the user of the method can see what it is (i.e. what's going to be done with it and what limitations there are on what they can pass). So if it really is a totally generic object, I see nothing wrong with calling the parameter 'object' (or 'obj' or 'o' depending on how professional you're being at the time). A more common situation is probably
public byte[] Encrypt(IDataSource dataSource)
... or similar interface-parameter declarations where the name can match the type because you really can pass any instance of that type.
I also like the word 'source' for parameters that are going to be transformed into a new format.
My code is full of this type of declaration because I like to make methods as generic as reasonably possible.
|
|
|
|
|
hey,do you know the answer?
|
|
|
|
|
hamid reza toosi wrote:
hey,do you know the answer?
Create a new project, connect to the database using a SqlConnection[^], set it's connectionstring and connect. Make sure that TCP/IP on SQL Server is enabled and that you can connect through the firewall.
Your question is a bit broad. It's like asking how to drive a car. Can you connect to a local server on your own PC?
Bastard Programmer from Hell
|
|
|
|
|
hamid reza toosi wrote: hey,do you know the answer?
Yep.
It isn't possible to "connect to" a file. Doesn't matter what kind of file it is.
Perhaps you were asking how to "connect to" a database. If that was the case then you need to specify the database.
|
|
|
|
|
Greetings!
I have an image representing the physical layout of a network, which is represented in terms of groups, layers, etc. Periodically I have show the network status, for which I have a library already. This status should be displayed on the image.
I can compare this with weather reporting where they show the map and display rain/snow/sun images for a specific area.
How can we logically divide the image into parts so that they can be mapped to the physical layout? And, how can we achieve this using ASP.NET?
Cheers
CNU
|
|
|
|
|
I'm trying to build a treeview over my system directories. My problem is that it runs really slow with directoryinfo.getDirectories() on my system with a large set of folders (5k folders in each subdir ). I have tested a set of different recursive functions to get directories and its subfolders, I have also tested with enumerate directory method.
Is there a way to do this better with better performance? Can i access it in any other way. I just want to build a treeview over a specific path and it should only include directories?
|
|
|
|
|
The problem with a number of .NET methods, such as good old GetDirectories() is they return an array, which means:
1. they cause latency, as you get the first (actually all) results only when everything has been collected and counted.
2. all the results are stored in memory at the same time, whether you need that or not.
The known remedies are:
- use more modern methods that return an enumerable, such as http://msdn.microsoft.com/en-us/library/dd383304.aspx[^] (requires .NET 4.0)
- built such methods yourself, based on Win32 API functions; that is what I did long before 4.0 emerged.
|
|
|
|
|
Thanks for the replay.
I've been working with/tested the enumerable method as well. It just improves a little bit.
Lets say i have root dir "rootdir" then I have subfolders A-Z and in each one of these folders i have a large number of folders.
I just want to view these folder structure in my treeview as fast as possible.
Maybe i need to include some kind of background worker to populate the treeview? As for now I use the standard msdn way to populate the treeview.
|
|
|
|
|
You should determine what exactly is slow; is it obtaining the information? or displaying it?
Warning: in my experience, enumerating large numbers of files/folders on a networked disk is always a lot slower than it is on a local disk. [ADDED] The one way around that is by re-organizing the folder hierarchy.[/ADDED]
How are you adding the info to the control? one by one? using SuspendLayout and BeginUpdate?
Anders Hedén wrote: some kind of background worker
won't work, a BGW can't access a WinForms Control; all it can do is gather information. But then, it won't improve latency, the work to be done remains the same, and you did not tell anything that indicates parallel processing could help.
FWIW: showing thousands of items in a user interface isn't really user friendly. A paged approach is recommended (look how CP shows some 25 messages at a time, not 1000s of them).
modified 20-Jan-12 8:35am.
|
|
|
|