Click here to Skip to main content
       

C#

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
QuestionAnother conversion problem (Prism)memberAndy_L_J18 Nov '12 - 11:07 
I am using Prism to handle IoC, I can do this in VB.NET:
 
Dim _regionManager As IRegion
Dim _container As IUnityContainer
...
 
Dim mainRegion As IRegion = _regionManager.Regions(RegionNames.MainRegion)
For Each v As View In mainRegion.Views
  mainRegion.Remove(v)
Next
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, GetType(MaterialView)
 
I am getting the following eror: non-invocable member ....Regions cannot be used as a method.
When I use this C# conversion:
IRegion mainRegion = _regionManager.Regions(RegionNames.MainRegion);
for each(var v in mainRegion.Views)
{
  mainRegion.Remove(v);
}
_regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(MaterialView));
Some hints as to why would be very helpfull.
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife

AnswerRe: Another conversion problem (Prism)protectorPete O'Hanlon18 Nov '12 - 11:39 
Regions is a collection. You access this using the indexer operator [..], so that would be _regionManager.Regions[RegionNames.MainRegion];

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos

CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Another conversion problem (Prism)memberAndy_L_J18 Nov '12 - 11:47 
Hi Pete, thanks for the help. I should have remembered this as I had the same issue a few days ago accessing the fields in a Datarow!
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife

QuestionSending bytes via internet? (info)memberclonze18 Nov '12 - 1:22 
I'm looking for information on networking.
 
I've been searching for a while now, but the best I was able to do was send bytes of data through my network using a very simple Server program/client program TCP setup in Microsoft Visual Studios 10. I gave the Server an IPAddress and told the client to connect to that specific address.
 
My end goal is learning how to create a simple multiplayer game using XNA Windows Game.
Any help, information, or direction is greatly appreciated!
AnswerRe: Sending bytes via internet? (info)memberEddy Vluggen18 Nov '12 - 1:50 
clonze wrote:
send bytes of data through my network using a very simple Server program/client program TCP

You'd use a socket, similar to this[^] example Smile | :)
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: Sending bytes via internet? (info)memberclonze18 Nov '12 - 3:54 
yes, i was able to use the socket to send bytes over my network; however, i'm completely lost when it comes to sending bytes over the internet! I've found that link before, but I didn't think it was what I was looking for. I'll look more into it now though, thanks.
GeneralRe: Sending bytes via internet? (info)memberEddy Vluggen18 Nov '12 - 4:42 
I'd work in a similar fashion; you connect to a public IP, and do your thing. The only annoying part being the firewalls and routers in between - some ports are closed by default.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

QuestionConverting from VB.NET [modified]memberAndy_L_J17 Nov '12 - 21:39 
In VB.NET I do this:
 
Public Property LogoutCommand As ICommand
...
LogoutCommand = New RelayCommand(AddressOf LogoutExecute, AddressOf CanLogoutExecute)
 
but when I try this in C#:
public ICommand LogoutCommand;
...
LogoutCommand = new RelayCommand(LogoutExecute, CanLogoutExecute);
...
private void LogoutExecute(){...}
private bool CanLogoutExecute()
{
 return true;
}
...
I get an error: "the best overloaded method match for RelayCommand(System.Action<object>, System.Predicate<object>) has some invalid arguments"
 
Here is the RelayCommand Class:
public class RelayCommand : ICommand
	{
		private readonly Action<Object> _execute;
		private readonly Predicate<Object> _canExecute;
 
		public RelayCommand(Action<object> execute): this(execute, null){	}
 
		public RelayCommand(Action<object> execute, Predicate<Object> canExecute)
		{
			if (execute == null)
			{
				throw new ArgumentException("execute");
			}
			_execute = execute;
			_canExecute = canExecute;
		}
 
		[DebuggerStepThrough()]
		public bool CanExecute(object parameter)
		{
			return _canExecute == null ? true : _canExecute(parameter);
		}
 
		public event EventHandler CanExecuteChanged
		{
			add { CommandManager.RequerySuggested += value; }
			remove { CommandManager.RequerySuggested -= value; }
		}
 
		public void Execute(object parameter)
		{
			_execute(parameter);
		}
 
	}
 
	public class RelayCommand<T> : ICommand
	{
		private readonly Action<T> _execute;
		private readonly Predicate<T> _canExecute;
 
		public RelayCommand(Action<T> execute): this(execute, null){}
 
		public RelayCommand(Action<T> execute, Predicate<T> canExecute)
		{
			if (execute == null)
			{
				throw new ArgumentException("execute");
			}
		}
 
		[DebuggerStepThrough()]
		public bool CanExecute(object parameter)
		{
			return _canExecute == null ? true : _canExecute((T)parameter);
		}
 
		public event EventHandler CanExecuteChanged
		{
			add { CommandManager.RequerySuggested += value; }
			remove { CommandManager.RequerySuggested -= value; }
		}
 
		public void Execute(object parameter)
		{
			_execute((T) parameter);
		}
 
	}
 
Any suggestions?
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife


modified 18 Nov '12 - 3:54.

AnswerRe: Converting from VB.NET [modified]mentorDaveyM6917 Nov '12 - 22:23 
Andy_L_J wrote:
AddressOf

... in your VB declarations is one clue here along with your error message.
 
Your RelayCommand constructor takes two delegates. In VB.Net you use the AddressOf operator to get a delegate for a method. In C# we use a delegate directly.
 
Try something like this to create delegates to your methods:
LogoutCommand = new RelayCommand(new Action<object>(LogoutExecute), new Predicate<object>(CanLogoutExecute));
 
Edit: Your LogoutExecute and CanLogoutExecute methods should both have one parameter of type object.
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)




modified 18 Nov '12 - 4:32.

GeneralRe: Converting from VB.NETmemberAndy_L_J17 Nov '12 - 22:54 
Cheers Dave, worked a treat.
 
I am self-learning C# after many years with VB.NET and some of conversions are making me crazy. Big Grin | :-D
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife

GeneralRe: Converting from VB.NETmentorDaveyM6918 Nov '12 - 7:10 
Keep persevering! Most things are fairly straight forward in my experience - I was once a VBer too, many years ago. Now I actually find it quite difficult to code in VB for the first 15 minutes or so, mainly cause I want to put a ; at the end of everything and wrap things in { } Wink | ;)
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



GeneralRe: Converting from VB.NETmemberAndy_L_J18 Nov '12 - 11:12 
I am enjoying the process Roll eyes | :rolleyes: however at the moment I get a couple hunderd moans from the compiler about missing ; and { } every time I build Big Grin | :-D
I don't speak Idiot - please talk slowly and clearly
 
"I have sexdaily. I mean dyslexia. Fcuk!"
 
Driven to the arms of Heineken by the wife

Questionfiltering column value in DevExpress grid viewmembereli1502197917 Nov '12 - 20:23 
Hi all,
 
I'm not sure this is the right forum,but I thought I'll give it a try,since not getting answers from DevExpress support center.
 
I'm using DevExpress GridView for winforms applications.
Also using VS2010 and Linq to SQL.
 
My grid view is binded to a LINQ table which represent a table in my database.
 
Let say I have a Person class with two properties - FirstName and LastName.
These two properties are persistent.
What I'm trying to do is to add a third property which will not be persistent and called FullName = LastName + FirstName.
This is working fine and the grid display the full name correctly.
My problem is when trying to filter values using the filter buttons in the column header,the dropdown list is empty...
 
When making FullName saved in the database - everything is OK.
Can anyone save me?
 
Thanks,
Eli
AnswerRe: filtering column value in DevExpress grid viewmembern.podbielski17 Nov '12 - 21:29 
Can you override some kind of grid_OnFilter event?
There would be just added filter for both FirstName and LastName. But really whole idea for that grid is wrong. Why? What happend whe you will have 1000, 10000, or 1000000 records? Grid will fetch all of them filter, sort and then show. More records then more time this will take.
No more Mister Nice Guy... >: |

QuestionhelpmemberAMIR ESLAMI17 Nov '12 - 9:08 
using (FileStream fs = File.OpenRead(path))
         {
             //HOW UTILIZE  BeginRead() IS PARAMETR
             fs.BeginRead();
         }

AnswerRe: helpmemberEddy Vluggen17 Nov '12 - 9:25 
A few points;
  • "Help" is a too generic subject; they're all looking for help
  • The question is hard to find; ask a question, explain what you tried, and why it didn't work
  • Reading a Stream is often-described pattern[^]. Do you really need the async version? Wouldn't ReadToEnd[^] be a bit simpeler?
Did you write/use an async method before?
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

AnswerRe: helpmvpAbhinav S18 Nov '12 - 20:58 
Sorry your question is not very clear.
BeginRead()[^] does not have any overloads that accept parameters.
WP7.5 Apps - XKCD | Calvin | SMBC | Sound Meter | Speed Dial

QuestionAccess to created controlmemberKKW_acd17 Nov '12 - 5:18 
Here is my code:
 
private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
{
     TabPage tp = new TabPage();
     tp.Text = "Data";
     System.Windows.Forms.CheckedListBox AvailableDataList = new system.Windows.Forms.CheckedListBox();
     AvailableDataList.Dock=DockStyle.Fill;
     tp.Controls.Add(AvailableDataList);
 
    for (bb = 0; bb < 8; bb++)
    {
        AvailableDataList.Items.Add("Bob");
        switch(SelectName(bb))
        {
            case false:
                AvailableDataList.SetItemChecked(bb, false);
                break;
            case true:
                AvailableDataList.SetItemChecked(bb, true);
        }
    tabControl1.TabPages.Add(tp);
}
 

private void button4_Click(object sender, EventArgs e)
{
    label1.text = AvailableDataList.Items.Count;
}
 
The code under the loadDataToolStripMenuItem works just fine.
I’m creating a CheckedListBox, populating it, then creating (adding) a TabPage, and placing the CheckedListBox on the new tab.
Problem is the created CheckedListBox AvailableDataList is not accessible in the button4_Click routine.
I don’t know how to make it public throughout the form.
Can someone help?
Thanks!
AnswerRe: Access to created controlmentorDaveyM6917 Nov '12 - 7:30 
At the moment it is a method level variable, you need to make it a class level one:
System.Windows.Forms.CheckedListBox AvailableDataList;
 
private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
{
     TabPage tp = new TabPage();
     tp.Text = "Data";
     AvailableDataList = new system.Windows.Forms.CheckedListBox();
     AvailableDataList.Dock=DockStyle.Fill;
     tp.Controls.Add(AvailableDataList);
 
    for (bb = 0; bb < 8; bb++)
    {
        AvailableDataList.Items.Add("Bob");
        switch(SelectName(bb))
        {
            case false:
                AvailableDataList.SetItemChecked(bb, false);
                break;
            case true:
                AvailableDataList.SetItemChecked(bb, true);
        }
    tabControl1.TabPages.Add(tp);
}
 
 
private void button4_Click(object sender, EventArgs e)
{
    if(AvailableDataList != null)
        label1.text = AvailableDataList.Items.Count;
}
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



QuestionHow do you programatically open a file in c# to append?memberXarzu17 Nov '12 - 1:05 
How do you programatically open a file in c# to append?
 
I tried searching online for an example and so far I have not found anything.
 
There is System.IO.StreamWriter and there is System.IO.StreamReader but there is no StreamAppend. Is there some way to use StreamWriter without overwritting the content of the existing file? Is there some way to use System.IO.Stream with some sort of appending criteria?
AnswerRe: How do you programatically open a file in c# to append?mentorDaveyM6917 Nov '12 - 1:35 
You can use a FileStream with FileMode.Append
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



AnswerRe: How do you programatically open a file in c# to append?memberEddy Vluggen17 Nov '12 - 9:32 
Xarzu wrote:
How do you programatically open a file in c# to append?

As explained in the tutorials you can Google.
 
Xarzu wrote:
I tried searching online for an example and so far I have not found anything.

"C# append text example". Nothing?
 
Xarzu wrote:
System.IO.StreamWriter and there is System.IO.StreamReader

You don't need a stream; File.AppendAllText[^] does as requested. Usage is simple;
File.AppendAllText(@"C:\Temp\Test.txt", "Text to append");
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

QuestionC# noob: Making Textbox entry a percentage, and Help with loopsmembermaul5916 Nov '12 - 18:46 
Hi, New here, and would be very thankful for any help someone can give me.
 
The code I am working for is a population estimator. It has 3 text boxes, the first is two enter the starting population, the second is to enter the daily increase in that population in a percentage, and the third is the number of days to multiply that by.
 
My first issue is with the second text box. I don't know how to enter the data as a percent. As of now it is only entering as a whole number, so I when I right in text box one the number 2, in box2 the number 30, and in three the number 10, I get the 302. Not 21.209 like it should be.
 
Secondly, it all displays in a listbox, and its supposed to loop for every day you enter. I've got the loop to loop by days, but it just runs the same calculation, I want it make every entry build off the last.
Example:
It should say
2
2.6
3.38
4.394
5.7122
etc
 
I've entered in the code below.
Thanks for any help!
 
private void calculateButton_Click(object sender, EventArgs e)
       {
           int organisms;
           int days;
           int growth;
           int population;
           int count = 1;
 
           if (int.TryParse(OrganismsTextbox.Text, out organisms))
           {
               if (int.TryParse(DailyTextbox.Text, out growth ))
 
               {
 
                   if (int.TryParse(DaysTextbox.Text, out days))
 
                       do
                       {
 
                           population = organisms + growth * days;
                           resultsListbox.Items.Add("The population For day " + count + " is " + population.ToString("n1"));
 

                           count = count + 1;
                       }
                       while (count <= days);

AnswerRe: C# noob: Making Textbox entry a percentage, and Help with loopsmvpRichard MacCutchan16 Nov '12 - 20:43 
You probably need to use double values rather than integers for your calculations, for greater accuracy. You also need to convert the number taken from the second textbox to a percentage; it's not 30 it is .30. You also need to change your calculation to calculate the growth in compound terms - I'm not sure of the actual formula.
One of these days I'm going to think of a really clever signature.

AnswerRe: C# noob: Making Textbox entry a percentage, and Help with loopsmvpOriginalGriff16 Nov '12 - 21:40 
There are a couple of simple things to do - firstly as Richard said, you need to use floating point values instead of integers:
2 + 30% is 2.6, but as an integer it is 2 again! Laugh | :laugh:
 
The second is that you are looping through the days, so you don't need to include the number of days in each calculation - just use the result from the previous day.
 
The third is that when you want an increased value, you can't just multiply by the percentage - 2 * 30% is 0.6, so your increase is 0.6, not your population. To increase your population, multiply but 1.0 + the percentage.
 
Finally, there is a better way to loop through the days: use a for loop instead of a while:
for (int day = 1; day <= days; day++)
   {
   ... calculate here
   }
 
So, my version would be:
   resultsListbox.Items.Add(string.Format("The population for day {0} is {1}", day, organisms));
   organisms *= 1.0 + percent;
with percent adjusted to 0.3 as Richard suggested.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 19 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid