|
Hello,
Please I want to get the upperbound of a dynamic array,
is there a function in c# to achive this?
thanks.
|
|
|
|
|
Dynamic Array[^]
Sathesh.
Blessed is the season which engages the whole world in a conspiracy of love.
|
|
|
|
|
You can find how many elements are in an array with the Length property.
C# doesn't have dynamic arrays - they are all fixed when you declare them, but you can fake it by creating a new array and copying the old elements to it. This is not a dynamic array however, as only the references you specifically change have the new size.
int[] orig = new int[] { 1, 2, 3, 4, 5, 6 };
int[] copy = orig;
int[] temp = new int[10];
for (int i = 0; i < copy.Length; i++)
{
temp[i] = copy[i];
}
copy = temp;
"copy" now refers to an array of ints with ten elements, but "orig" tsill referes to an array of six.
If you want a dynamic array like structure, you would be better off using a List<T> which has a ToArray method if you need it.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
OriginalGriff wrote: If you want a dynamic array like structure, you would be better off using a List<t>
Or switch to VB?
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
riced wrote: Or switch to VB?
Wash your keyboard out with soap!
I would never recommend anyone switch to VB.
Well, except Estate Agents.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
The smiley saved you from a 1 vote
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Thanks all,
I discovered that when using the foreach... loop to access
an array, you don't need to know the dimension before hand.
it works great.
thanks again for your contributions
|
|
|
|
|
Where did you find a dynamic array?
|
|
|
|
|
He looked under the VB sofa and there it was.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Hi everyone,
I have the following issue. I use the following code to retrieve all data row from an mssql database and during the process I update some values.
The issue I have is that it only updates the first row in the database. All other rows which should be updated (field: WEB_OBEZ,...) are NULL.
Does someone have an idea or can explain why it only updates the first row ?
Thank you very much!
private string FixOBez()
{
SqlConnection dbconn = new SqlConnection(this.sqlconn);
try
{
dbconn.Open();
SqlDataReader sqlreader = null;
SqlCommand mycmd = new SqlCommand("SELECT * FROM dbo.testdata", dbconn);
sqlreader = mycmd.ExecuteReader();
while (sqlreader.Read())
{
string obez = sqlreader["O_BEZ"].ToString();
string okuerzel = sqlreader["O_KURZ"].ToString();
string[] lines = GetNewOBez(obez);
SqlCommand sql2 = new SqlCommand("UPDATE dbo.testdata SET WEB_OBEZ1 = '" + lines[0] + "',WEB_OBEZ2 = '" + lines[1] + "',WEB_OBEZ3 = '" + lines[2] + "' WHERE O_KURZ = '" + okuerzel + "'",dbconn);
sql2.ExecuteNonQuery();
return "OK";
}
}
catch (Exception ex)
{
return ex.Message;
}
return "OK";
}
Bye,
ANeuby
|
|
|
|
|
Found the issue. The return was in the wrong line.
|
|
|
|
|
I have Gridview with AutoGenerateColumns to true(as I don't know how many columns will come). From database I am getting binary data. When I bind data table to gridview it displays checkbox with checked and unchecked. I need to display as 0 or 1. How can I do this?
|
|
|
|
|
You can do it in multiple ways like - converting that boolean property to a string property in gridview source object, make use of template in griview.
|
|
|
|
|
|
Change your query to return a string or integer instead of binary using convert() in TSQL (assuming SQL Server)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank u Holmes, working fine
|
|
|
|
|
Hi
I have used Visual Studio 2010 Express to develop a Windows application. I have published the program and the users install it from a shared location on a central computer. I have also done several updates that I have published without any problems. When the users run the program it first checks for updates and so far it has always picked up if there was an update and installed it.
The program is installed from a folder '\\MyServer\EPR\Installation\Install\' and the update location is '\\MyServer\EPR\Installation\Updates\'.
This morning I tried to roll out a new update. I copied the published files to the Updates folder as I have always done, but when I ran the application it checked for updates, but then it still ran the old version and did not install the new version.
The old version is 4.0.3.1 and the new version is 4.0.4.0.
Any ideas on what the problem can be?
At this stage my morning has been a complete waste and I feel very frustrated.
Regards.
Kobus
|
|
|
|
|
kbalias wrote: When the users run the program it first checks for updates
How does it do this?
kbalias wrote: Any ideas on what the problem can be?
Without seeing your code it is impossible to guess.
It's time for a new signature.
|
|
|
|
|
I need to create a billing software.At the sales page i need to create a listview and with in the listview i need to create multiple componets for typing sales details...I have gone through the web but i didnt get so help me...........
|
|
|
|
|
Winforms or webform - you do not say.
Listview does not accept components you need to use a datagridview (assuming winform)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you working with windows forms you can check the XPTable article here in codeproject. It can fit you requirements.
If not you can create your own Listview, since default one is not editable.
|
|
|
|
|
Hi, fellow CodeProject members. I'm writing an application that contains a menu strip and a tool strip. The main application window is an MDI Container and on the left-hand side of the window is a splitter with a TreeView control. Depending on the TreeView's selected node I would like to enable/disable certain tool strip and menu strip items. What is the best way to go about doing so?
I currently do something like this:
private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (mainTreeView.SelectedNode == null) return;
TreeNode selectedNode = mainTreeView.SelectedNode;
switch (selectedNode.Level)
{
case 0:
break;
case 1:
if (selectedNode.Parent.Name == "RootNode1")
{
}
else if (selectedNode.Parent.Name == "RootNode2")
{
}
break;
}
}
}
There are currently eight items total for which I would like to toggle depending on the TreeView selection. I am only wanting to toggle the 'Enabled' state for the items. That's because, for example, root node 1 is selected so the user can only select "New Item...". Or if a child of root node 1 is selected then the user can choose "New Item...", "Edit Item..." or "Delete Item...". And root node 2 holds a different type of item so root node 1 items shouldn't be enabled in that case.
Is there a different way to go about this altogether? Do I have it all (or partially) incorrect? Or should I simply create a method for each case, such as "void ToggleRootNodeItems(int OneOrTwo)" and "void ToggleChildNodeItems(int ParentIsRootOneOrTwo)"?
I hope I explained my question fully. If you need more information I can provide you with whatever you need. Thanks much!
|
|
|
|
|
Using a switch or creating a different method for each node are valid ways to do it.
My preferred method in this case would be to use the Tag property of each TreeNode to store a List of ToolStripItem s that should be enabled when that node is selected. When the nodes are created (or in the form constructor, whichever is applicable) initialize the List s. Then in the selection change handler disable everything, then cycle through the list of ToolStripItem s for the selected node and re-enable each one.
Like this:
internal MyConstructor()
{
List<ToolStripItem> items = new List<ToolStripItem>();
items.Add(newItemButton);
items.Add(editButton);
rootNode1.Tag = items;
items = new List<ToolStripItem>();
items.Add(deleteItemButton);
items.Add(crashTheComputerButton);
rootNode2.Tag = items;
}
private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (mainTreeView.SelectedNode == null) return;
TreeNode selectedNode = mainTreeView.SelectedNode;
foreach(ToolStripItem item in )
{
item.Enabled = false;
}
List<ToolStripItem> applicableItems = selectedNode.Tag as List<ToolStripItem>;
if (applicableItems == null)
{
return;
}
foreach(ToolStripItem item in applicableItems)
{
item.Enabled = true;
}
}
|
|
|
|
|
Wow, thanks. LoL. I had no idea about the "Tag" property for TreeNode objects. I'll play with the example you gave and if I need anymore information I'll come back. Thanks a lot.
|
|
|
|
|
Alright, after reading your post and researching this a little bit, I finally implemented the code. I'll tell you, it looks 10x cleaner. LoL. Another thing I noticed is that when I ran the Code Metrics (VS2010) before, the "Maintainability Index" for that particular form was around 46 or 48 I believe. After changing to the method you described it went up to 55. I still have a few areas that I need to break into separate methods, which I believe may bring it up some more.
Thanks a lot for the help.
|
|
|
|