|
use System.Collections.Generics.SortedList instead of System.Collections.SortedList. If you are using 2005, Visual Studio defaults to the wrong namespace when creating your class files for you.
|
|
|
|
|
SortedList<string, string> sr = new SortedList<string, string>();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
your code does not compile at all. There isn't a single line without errors.
If you fix all the typos you would get one compile-time error (cannot implicitly convert...).
So you have to add an explicit string casting (or replace the old SortedList by a generic one).
If you want to ever become a successful programmer you need to become meticulous right away.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I used the system.collection.generic but it doesn't help as well.
|
|
|
|
|
Visual Studio 2005 is fine for .NET 2.0 (the first version offering generics).
You have another typo. Read the documentation and follow it to the letter.
[EDIT] In the previous version of your reply, the one containing:
Ok thanks,
But there is a problem- I use VS2005.
I wrote :
using System.Collections.Generics;
(i wrote using system.collection too).
But I get error saying that the type or namespace Generics does not exist in namespace system.collection
you had another typo.
[/EDIT]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Does this code even compiles?
Following works perfectly fine for me:
SortedList<string,string> sr=new SortedList<string,string>();
sr.Add("abc","def");
string k=sr["abc"];
To be on the safer side, you can use TryGetValue method.
जय हिंद
|
|
|
|
|
Here is a snippet from my code:
SortedList <string, string=""> focus_URLS = new SortedList <string, string="">();
focus_URLS.Add("AR Coater","ARC+Lab&MachineName=AR+Coater&TypeID=2&StationID=1&datatype=0");
string focus_url_end = focus_URLS["AR Coater"];
but i receive error saying the key wasn't found
|
|
|
|
|
Does anyone know the problem?
|
|
|
|
|
Earlier today I had this exact error.
In my case it was because the key had been added with a preceding space. i.e. key = " abc", search = dict["abc"] <== error
So ensure that there are are no extraneous spaces in either the key, when added to the list, or your literal in the lookup.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
OH LOL it seems that it's working now.
I so hate this kind of error- you can do everything and you won't fix it because you don't think of such things
|
|
|
|
|
Hi,
Can someone please help me.
I am getting error: The process cannot access the file 'c:\reports\PaymentDetailReport.xml' because it is being used by another process. in following function.
This method is suppose to be called couple of times. but at second time, it throws the error. I have even closed tw.
private void saveReport(string reportName, string data)
{
if (reportName == "PaymentReport")
{
StreamWriter tw = new StreamWriter(_documentName);
tw.WriteLine(data, true);
StreamWriter masterPSDR = File.AppendText("C:\\reports\\masterPSDR.xml");
masterPSDR.WriteLine(data, true);
tw.Close();
masterPSDR.Close();
}
|
|
|
|
|
You may need to call Flush()[^] on yur StreamWriters.
Put them both in using blocks too
using(StreamWriter tw = new StreamWriter(_documentName))
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
sonya_rbi wrote: I have even closed tw
You're too kind. Of course, if you create or open something, you have to close it too.
My bet is you are victim to the goodness of Windows or one of the utilities you added. Here is a standard text snippet explaining the risk you are under:
---------------
if you want write or delete access (anything other than read access) to a file that just got created (by yourself or someone else, does not matter), chances are you will find the file is being accessed by some other process, and your access is not granted.
The other process very likely is some server code that is there to assist you somehow. Candidates are:
- anti-virus software (Norton, McAfee, whatever)
- indexing software (Google Desktop, MS Office, whatever)
The common thing is these packages are looking all the time for new files, so they can inspect them.
Microsoft is aware of the consequences; Windows Explorer will try rename and delete attempts up to five times (with one-second interval), and only reports failure if the action continues to fail for that time.
The solution:
1. either use a different file name
2. or remove all background reader candidates (bad idea)
3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer
for this)
BTW: if all you need is Read, make sure to allow others to read as well, i.e.
use File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)
---------------
In my experience, this happens when the succesive open/write/close cycles are more than 1 second apart; if you do it more frequently, you won't have any trouble (I log stuff with open/write/close all the time).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi Everyone,
I have been trying to figure out an elegant way to get the result I want to something that must be a very common issue; getting the user to choose the COM port from a list. I can't find a neat solution out there, I thought maybe someone here would have a suggestion.
The setup is a new WPF window is spawned that just contains a ComboBox (for now) for choosing the COM port, this needs to be double bound. The first binding is to get the array of strings from the SerialPort.GetPortNames() static method, these will be the items in the list.
portList = new System.Collections.ArrayList(16);
foreach (string port in System.IO.Ports.SerialPort.GetPortNames())
{
portList.Add(port);
}
comPortListBox.ItemsSource = portList;
The next binding is to SelectedItem which should get and set the value in the properties of the application. When the window is closed, the properties are saved.
Properties.Settings.Default.SerialInterfaceComPort
Properties.Settings.Default.Save();
I have included how I am currently making it work below, there is a lot of code tho and it has some bugs to do with the properties value returning null sometimes.
I should point out that in the example the baud rate list works perfectly as it is based on a list of values in the XAML and I don't have to create it from a string array. Although, if anyone knows how to get a list of valid port speeds for a particular port that could be made pretty fancy.
Any suggestions on how to make this nice and elegant with better data binding would be great!
Thanks
Ed
public SerialSettingsWindow()
{
InitializeComponent();
portList = new System.Collections.ArrayList(16);
foreach (string port in System.IO.Ports.SerialPort.GetPortNames())
{
portList.Add(port);
}
tempComPort = Properties.Settings.Default.SerialInterfaceComPort;
tempBaudRate = Properties.Settings.Default.SerialInterfaceBaudRate;
comPortListBox.ItemsSource = portList;
int portIndex = portList.BinarySearch(Properties.Settings.Default.SerialInterfaceComPort);
if (portIndex >= 0 && portIndex < comPortListBox.Items.Count)
{
comPortListBox.SelectedIndex = portIndex;
}
else
{
comPortListBox.SelectedIndex = -1;
}
baudRateListBox.DataContext = Properties.Settings.Default;
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SerialInterfaceComPort = tempComPort;
Properties.Settings.Default.SerialInterfaceBaudRate = tempBaudRate;
Properties.Settings.Default.Save();
this.Close();
}
private void doneButton_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SerialInterfaceComPort = comPortListBox.SelectionBoxItem.ToString();
Properties.Settings.Default.Save();
this.Close();
}
}
|
|
|
|
|
|
Hi Ennis,
Thanks very much for your response. You are absolutely right about the SelectedItem thing I don't know how I didn't manage that already. Also, I quite like my comments they help me remember why I did stuff!
I guess it would be nice to have some cunning syntax that allowed you to bind the ComboBox directly to the string array from GetPortList() but I suppose it's not a big deal to do the copy really.
It's nice to know I am improving my c# so I have not made too many obvious style errors!
I'll post my final code below as I expect these posts hang around and someone else may find it useful.
Cheers
Ed
namespace Sensor_Controller_User_Interface
{
public partial class SerialSettingsWindow : Window
{
private string tempComPort;
private int tempBaudRate;
private System.Collections.ArrayList portList;
public SerialSettingsWindow()
{
InitializeComponent();
portList = new System.Collections.ArrayList(16);
foreach (string port in System.IO.Ports.SerialPort.GetPortNames())
{
portList.Add(port);
}
tempComPort = Properties.Settings.Default.SerialInterfaceComPort;
tempBaudRate = Properties.Settings.Default.SerialInterfaceBaudRate;
comPortListBox.ItemsSource = portList;
comPortListBox.SelectedItem = Properties.Settings.Default.SerialInterfaceComPort;
baudRateListBox.DataContext = Properties.Settings.Default;
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SerialInterfaceComPort = tempComPort;
Properties.Settings.Default.SerialInterfaceBaudRate = tempBaudRate;
Properties.Settings.Default.Save();
this.Close();
}
private void doneButton_Click(object sender, RoutedEventArgs e)
{
Properties.Settings.Default.SerialInterfaceComPort = comPortListBox.SelectionBoxItem.ToString();
Properties.Settings.Default.Save();
this.Close();
}
}
}
|
|
|
|
|
Hi everyone,
I am having a tricky problem, I want some slightly unusual behaviour from a checkbox and can't seem to figure it out. Any suggestions would be most welcome. The behaviour I want is:
1. The CheckBox is enabled and ready for the user to click, IsChecked represents a bound boolean value stored in a data structure
2. The user clicks the CheckBox causing the click event to fire but the bound value in the data structure is NOT updated and the visual representation of the CheckBox is NOT updated but it is disabled to stop further clicking
3. The click event triggers a message to be sent to a remote device which takes some time to respond
4. The remote device responds causing the data structure to be updated with the new value, the binding then updates the isChecked status and the CheckBox gets reenabled for further clicking
The problem I have is that although a OneWay data binding works at not updating the data structure when the CheckBox is clicked, the visual representation does change (which I think is odd, shouldn't IsChecked now act like a pointer to the value in the data structure).
I can reverse the change in the Click() event and do the disable there as well but this is pretty messy. I can also have the set property of the data structure value to set an isEnabled value which is also bound to reenable the CheckBox but that seems messy too.
Is there a clean way to do this? Perhaps with a derived CheckBox class? How can I stop the visual representation getting updated?
Thanks
Ed
|
|
|
|
|
|
benjamin yap wrote: i wan to create on a c# application. not a .net application
AFAIK C# does not exists without .Net. Hence, not possible.
जय हिंद
|
|
|
|
|
i mean
not .aspx application... but a .exe app
|
|
|
|
|
Start by looking in to the MonthCalendar control. Customize to create a planner.
As far as searching goes, first page of Google search results will give you what you need (Although the control is not free). There is also an article here at CP(I just saw one, might be many more). Go through it.
जय हिंद
|
|
|
|
|
benjamin yap wrote: issit possible?
Yes.
benjamin yap wrote: can give me some hints on how should i start
Requirements
|
|
|
|
|
Hello,
Do someone can provide me with a simple full text search that search for english and arabic words.
I tried Lucene.dll but it not supporting arabic words.
best regards.
Elie
dghdfghdfghdfghdgh
|
|
|
|
|
Try to compose your own code, we'll be happy to help you with any bugs.
or, try rentacoder[^] if you're willing to pay to get it done, no one does work for free.
|
|
|
|
|
I'm implementing a filter, and need to indicate if the filters applied are hiding one or more row, or if all the rows are visible.
My first thought was to use DataGridView.DisplayedRowCount() , but it returns the number of rows that are actually shown on the screen. If there are enough rows to trigger a vertical scroll this isn't the same because rows that are off the top/bottom of the list are not counted.
Is there another method/property I'm not seeing, or will I have to iterate over the entire Rows collection?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|