|
sorry about that scott, i don't mean to offend, just i've been reading up on it and alot of people have said to use these third party applications, when they are not even needed. Thanks for that, i will look into it when i get home later on.
All i am looking for is to sort all my numbers out, so i could have 10 5's, 20 1's etc. and they would be displayed like this:
5 = 10, 1 = 20 etc. but i'm not sure your code gives me a full answer, i already knew the code you posted, but i will look further into it later.
Remember i wasn't after adding all the integers together, i was after counting the amount of same integer, e.g. the amount of ones i have.
thanks
|
|
|
|
|
My bad... sorry. I think the knowledge representation is the tricky part here. Once you figure out how to represent the information, the rest is a snap. Have a look, there are many ways to implement this. So I put together an example using .NET 3.5 as to what you can do. If you're using 2.0, you'll have to make the Action and Predicate delegate yourself, but it will work the same. The code will compile and run.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountTest {
class Program {
static void Main(string[] args) {
String test = "1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9";
List<bucket> items = new List<bucket>();
String[] split = test.Split(',');
foreach (String s in split) {
Bucket b = new Bucket{ Key = s, Count = 1};
Bucket searchedBucket = items.Find(new Predicate<bucket>(bkt => b.Key.Equals(bkt.Key)));
if (searchedBucket == null) {
items.Add(b);
} else {
searchedBucket.Count++;
}
}
items.ForEach(new Action<bucket>(b => Console.WriteLine(b.ToString())));
Console.ReadLine();
}
}
public class Bucket {
public string Key;
public Int32 Count;
public override string ToString() {
return String.Format("{0} {1}{2}", Count, Key, Count > 1 ? "'s" : "");
}
}
}
</bucket></bucket></bucket></bucket>
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
If I understand your request, you're looking to count the number of occurances of each 1, 5, 10, 100, and so on, on each line or file?
Easy. Use a Dictionary, or some other Key/Value pair collection to track each item and the count for it. Off the top of my head, the core of something like this would look similar to this:
Dim itemCounts As Dictionary(Of String, Integer)
'open file and read a line here...
Dim values() As String = lineRead.Split(New Char() {","c})
For Each value As String In values
If itemCounts.ContainsKey(value) Then
' If the key is already in the collection, up the count by 1.
itemCounts(value) += 1
Else
' If the key doesn't exist yet, add the key with the count of 1.
itemCounts.Add(value, 1)
End If
Next
...
Return itemCounts
You'd treat each value as a key to the collection, whereupon each value associated with the key would be the count of the occurances of those keys.
|
|
|
|
|
thanks for the reply, what exactly do i need for this code?
e.g. system. what? Personally i have not seen code like this before, i tried putting it inside my class and everything is wrong.
I know what you posted was psudo code but i cannot figure it out. What exactly is item counts? if that the streamreader name you gave? It's abit confusing your code :S, my form won't recognise the dictionary terms or the itemcount itself. sorry about this
please can you explain more in c# terms, i have only been using the software a few months and still fuzzy on some things. thanks
modified on Tuesday, April 8, 2008 8:34 PM
|
|
|
|
|
Hi,
has anyone ever needed to report progress when (de)serializing objects? I have implemented loading/saving project files (for my application) via serialization and this could take up to 5-10 sec, depending on what's in the project. So I'd like to do it asychronously and report progress. Is there any way how to find out (de)serialization progress(perc completed)?
thanx
zilo
|
|
|
|
|
I remember reading an article about it but I can't remember where I found it. I am more than sure Google has the answer[^]
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
How do you think your post was helpful to me?
zilo
|
|
|
|
|
If my post was not helpful, you can ignore it. However, If my post was not helpful, I am afraid that none of the post will be helpful for you.
Good luck
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Thank you very much for help. Next time please don't bother me with such answers
zilo
|
|
|
|
|
Ok, I won't. If you don't want to you will not get help from me.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
That depends on how you're serializing objects. If you're just calling a single method that walks an object graph, then you're not going to get anny progress information back from that method. If you're writing the code to walk the object graph, serializing each node yourself, then you can put some extra code in there to report some kind of progress.
But, if you have no way of knowing when the end of the graph is, you really can't report any percentage of progress completed. So, you're only other option would be to use a non-progressing progress bar. It'll just show something is still happening, but not report real progress.
|
|
|
|
|
Thanx for answer.
that's what I was afraid of... I was hoping there might be at least something saying on what position of the Stream is the serializer currently, that would be more than enough for my needs...
btw I'm using BinaryFormatter.Deserialize (Serialize) and I'm implementing the ISerializable interface (GetObjectData and Constructor) for classes to serialize.
I'll just say that something is happening...
zilo
|
|
|
|
|
|
I use the function bellow to create a DataGridViewComboBoxCell in databound gridview in a datagridviewtextboxcolumn. When I enter the cell I can see the dropdown arrow, but when i click on the arrow nothing happens.
Can anybody help me please
Maris
<br />
private void AddComboBox(int index, string selectedValue, List<string> projects)<br />
{<br />
if (projects == null)<br />
throw new NullReferenceException("Project list vas empty");<br />
DataGridViewComboBoxCell aCell = new DataGridViewComboBoxCell();<br />
foreach (string s in projects)<br />
{<br />
aCell.Items.Add(s);<br />
}<br />
aCell.Value = selectedValue;<br />
aCell.DropDownWidth = 1000;<br />
_dataGridView.Rows[index].Cells[0] = aCell;<br />
}<br />
private void _dataGridView_CellMouseEnter(object sender, DataGridViewCellEventArgs e)<br />
{<br />
if (e.RowIndex >= 5 && e.RowIndex <= 9)<br />
{<br />
List<string> projectList = _domainFacade.GetProjects();<br />
string listValue = projectList[0];<br />
AddComboBox(e.RowIndex, listValue, projectList);<br />
}<br />
}<br />
|
|
|
|
|
|
|
So
your code may have incorrect way.
please check your code is correct.
i think u must add cellcolumn.instead of assign to cell.
because of we want to add our cell column control to datagridview control collections.
|
|
|
|
|
Hello all. I'm trying to allow a user to save a text file and only a text file. My filter is "Text files (*txt)|*txt" This seems to be set up fine but when I save a file, I can save as .doc. This shouldn't happen, at least that's what I thought.
Where am I going wrong?
Lester
http://www.lestersconyers.com
|
|
|
|
|
You're making the assumption that the SaveAs dialog restricts the extension the user can use. Wrong. This only filter the filenames listed in the dialog box. You're code has to make sure the extension is correct, and fix it if it's not, after the user clicks OK and before you open the stream to start writing your data.
|
|
|
|
|
I have used WndProc() override to perform PostMessage(this.listViewEx2.Handle, WM_VSCROLL, e.WParam, IntPtr.Zero);
I managed to bring it to some shape now but came up with some amazingly annoying issues!
In all my issues here are as follows
1. scroll works only by thumb tack
2. mouse scroll doesnt trigger listview2
3. scrolling using the bar and not the thumb tack doesnt scroll the listview2
4. how do i prevent the two events from going into an infinite loop when i paste the code for ListView2_Scroll?
Hoping for an express response!
-
Roger
|
|
|
|
|
Perhaps if you specify what you're trying to do, we can provide you with an alternate, managed way to do it.
|
|
|
|
|
private void listViewEx1_Scroll(object Sender, LifeHouse.ListViewEx.ListViewEx.MyScrollEventArgs e)<br />
{<br />
try<br />
{<br />
Int16 hi = (Int16)((int)e.WParam >> 16);<br />
Int16 lo = (Int16)(int)e.WParam;<br />
IntPtr temp;<br />
if (e.Orientation == ScrollOrientation.VerticalScroll)<br />
{<br />
if (lo == 5)<br />
{<br />
if (SetScrollPos(this.listViewEx2.Handle, SBS_VERT, hi, true) != 0)<br />
{<br />
temp = (IntPtr)(4 + 0x10000 * hi);<br />
PostMessage(this.listViewEx2.Handle, WM_VSCROLL, temp, IntPtr.Zero);<br />
}<br />
}<br />
else<br />
{<br />
PostMessage(this.listViewEx2.Handle, WM_VSCROLL, e.WParam, IntPtr.Zero);<br />
}<br />
}<br />
<br />
if (e.Orientation == ScrollOrientation.HorizontalScroll)<br />
{<br />
if (lo == 5)<br />
{<br />
SetScrollPos(this.listViewEx2.Handle, SBS_HORZ, hi, true);<br />
PostMessage(this.listViewEx2.Handle, WM_HSCROLL, (IntPtr)(4 + 0x10000 * hi), IntPtr.Zero);<br />
}<br />
else<br />
{<br />
PostMessage(this.listViewEx2.Handle, WM_HSCROLL, e.WParam, IntPtr.Zero);<br />
}<br />
}<br />
}<br />
<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.ToString());<br />
}<br />
}
This is my code that is supposed to scroll ListViewEx2 when ListViewEx1 is clicked. I am able to achieve a scroll with the thumbtrack of ListViewEx1 but when i hold and drag the scrollbar there is no change in ListViewEx2's scroll in contents (that is, only the scroll bar moves while the content staying put).
Mouse's wat scroll event could trigger a similar scroll?
How to get both scrolls to sync?
|
|
|
|
|
|
If you want to sync the scrolling of two lists, here might be the right way to get it:
- for each item in the master list, identify the corresponding item in the slave list,
and add a (masterItem, slaveItem) to a Hashtable/Dictionary;
- whenever the master list scrolls, determine the new top master item, look up the
corresponding slave item, and scroll the slave list using ListView.TopItem,
ListBox.TopIndex or a similar property.
When the master list does not offer a scrollChanged event, use a Windows.Forms.Timer to do
the above periodically.
That should be much simpler than manipulating Windows messages, WndProc and the like.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
That's the first way that i went by but that aint what the project requires!
When the user clicks on the scrollbar and scrolls the other listview has to be in sync. that is behave as though the user is clicking on two listviews at once and scrolling.
That is the reason i've been trying to override WndProc()!
Can anyone figure a way?
|
|
|
|
|