|
What are you binding the textbox to?
|
|
|
|
|
Atually I'm developing a documents In-System and this is the document no.
I face this problem when I convert the textbox order to be Right To Left
Thanks
modified on Thursday, May 1, 2008 8:12 AM
|
|
|
|
|
when i am trying to insert i the patient detail in the BINARY SEARCH TREE it give me the following error "The best overload method for IBSTree.Insert(System.Icomparable) has some invalid arguments".
<br />
using System;<br />
using System.Collections;<br />
<br />
<br />
<br />
public interface IPatient<br />
{<br />
string FirstName { get; set; }<br />
<br />
<br />
}<br />
<br />
<br />
using System;<br />
using System.Collections;<br />
<br />
<br />
<br />
public class Patient: IPatient<br />
{<br />
private string fname;<br />
<br />
public string FirstName<br />
{<br />
get<br />
{<br />
return fname;<br />
}<br />
set<br />
{<br />
fname = value;<br />
}<br />
}<br />
public int CompareTo(IPatient obj)<br />
{<br />
Patient p1 = (Patient)obj; <br />
return fname.CompareTo(p1.fname);<br />
} <br />
}<br />
<br />
using System;<br />
using System.Collections;<br />
<br />
public class BTreeNode<br />
{<br />
private IComparable item;
private BTreeNode lchild;
private BTreeNode rchild;
<br />
public BTreeNode(IComparable item)<br />
{<br />
this.item = item;<br />
lchild = null;<br />
rchild = null;<br />
}<br />
<br />
public IComparable Item<br />
{<br />
get { return item; }<br />
set { item = value; }<br />
}<br />
<br />
public BTreeNode LChild<br />
{<br />
get { return lchild; }<br />
set { lchild = value; }<br />
}<br />
<br />
public BTreeNode RChild<br />
{<br />
get { return rchild; }<br />
set { rchild = value; }<br />
}<br />
}<br />
<br />
<br />
public class BSTree : IBSTree<br />
{<br />
private BTreeNode root;<br />
public BSTree()<br />
{<br />
root = null;<br />
}<br />
<br />
public bool IsEmpty()<br />
{<br />
return root == null;<br />
}<br />
<br />
public bool Search(IComparable item)<br />
{<br />
return Search(item, root);<br />
}<br />
<br />
private bool Search(IComparable item, BTreeNode r)<br />
{<br />
if (r != null)<br />
{<br />
if (item.CompareTo(r.Item) == 0)<br />
return true;<br />
else<br />
if (item.CompareTo(r.Item) < 0)<br />
return Search(item, r.LChild);<br />
else<br />
return Search(item, r.RChild);<br />
}<br />
else<br />
return false;<br />
}<br />
<br />
<br />
public IComparable PartialSearch(IComparable item)<br />
{<br />
return PartialSearch(item, root);<br />
}<br />
<br />
private IComparable PartialSearch(IComparable item, BTreeNode r)<br />
{<br />
if (r != null)<br />
{<br />
if (item.CompareTo(r.Item) == 0)<br />
return r.Item;<br />
else<br />
if (item.CompareTo(r.Item) < 0)<br />
return PartialSearch(item, r.LChild);<br />
else<br />
return PartialSearch(item, r.RChild);<br />
}<br />
else<br />
return null;<br />
}<br />
<br />
<br />
public void Insert(IComparable item)<br />
{<br />
if (root == null)<br />
{<br />
root = new BTreeNode(item);<br />
<br />
}<br />
else<br />
Insert(item, root);<br />
}<br />
<br />
private void Insert(IComparable item, BTreeNode ptr)<br />
{<br />
if (item.CompareTo(ptr.Item) < 0)<br />
{<br />
if (ptr.LChild == null)<br />
{<br />
ptr.LChild = new BTreeNode(item);<br />
<br />
}<br />
else<br />
Insert(item, ptr.LChild);<br />
}<br />
else<br />
{<br />
if (ptr.RChild == null)<br />
{<br />
ptr.RChild = new BTreeNode(item);<br />
<br />
}<br />
else<br />
Insert(item, ptr.RChild);<br />
}<br />
}<br />
<br />
public void Delete(IComparable item)<br />
{<br />
BTreeNode ptr = root;
BTreeNode parent = null;
while ((ptr != null) && (item.CompareTo(ptr.Item) != 0))<br />
{<br />
parent = ptr;<br />
if (item.CompareTo(ptr.Item) < 0)
ptr = ptr.LChild;<br />
else<br />
ptr = ptr.RChild;<br />
}<br />
<br />
if (ptr != null)
{<br />
if ((ptr.LChild != null) && (ptr.RChild != null))<br />
{<br />
if (ptr.LChild.RChild == null)
{<br />
ptr.Item = ptr.LChild.Item;<br />
ptr.LChild = ptr.LChild.LChild;<br />
}<br />
else<br />
{<br />
BTreeNode p = ptr.LChild;<br />
BTreeNode pp = ptr;
while (p.RChild != null)<br />
{<br />
pp = p;<br />
p = p.RChild;<br />
}<br />
ptr.Item = p.Item;<br />
pp.RChild = p.LChild;<br />
}<br />
}<br />
else
{<br />
BTreeNode c;<br />
if (ptr.LChild != null)<br />
c = ptr.LChild;<br />
else<br />
c = ptr.RChild;<br />
<br />
if (ptr == root)
root = c;<br />
else<br />
{<br />
if (ptr == parent.LChild)<br />
parent.LChild = c;<br />
else<br />
parent.RChild = c;<br />
}<br />
}<br />
<br />
}<br />
}<br />
<br />
public void PreOrderTraverse()<br />
{<br />
PreOrderTraverse(root);<br />
Console.WriteLine();<br />
}<br />
<br />
private void PreOrderTraverse(BTreeNode root)<br />
{<br />
if (root != null)<br />
{<br />
Console.Write(root.Item);<br />
PreOrderTraverse(root.LChild);<br />
PreOrderTraverse(root.RChild);<br />
}<br />
}<br />
<br />
public void InOrderTraverse()<br />
{<br />
InOrderTraverse(root);<br />
Console.WriteLine();<br />
}<br />
<br />
private void InOrderTraverse(BTreeNode root)<br />
{<br />
if (root != null)<br />
{<br />
InOrderTraverse(root.LChild);<br />
Console.WriteLine(root.Item);<br />
InOrderTraverse(root.RChild);<br />
}<br />
}<br />
<br />
public void PostOrderTraverse()<br />
{<br />
PostOrderTraverse(root);<br />
Console.WriteLine();<br />
}<br />
<br />
private void PostOrderTraverse(BTreeNode root)<br />
{<br />
if (root != null)<br />
{<br />
PostOrderTraverse(root.LChild);<br />
PostOrderTraverse(root.RChild);<br />
Console.Write(root.Item);<br />
}<br />
}<br />
<br />
public void Clear()<br />
{<br />
root = null;<br />
}<br />
<br />
public ArrayList AllItems()<br />
{<br />
ArrayList items = new ArrayList();<br />
AllItems(root, items);<br />
return items;<br />
}<br />
<br />
private void AllItems(BTreeNode root, ArrayList keys)<br />
{<br />
if (root != null)<br />
{<br />
AllItems(root.LChild, keys);<br />
keys.Add(root.Item);<br />
AllItems(root.RChild, keys);<br />
}<br />
}<br />
}<br />
<br />
using System;<br />
using System.Collections;<br />
<br />
namespace PatientName<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
int choice;<br />
IPatient p1 = new Patient();<br />
IBSTree container = new BSTree();<br />
Console.WriteLine("Enter the first Name of the patient:");<br />
p1.FirstName = Console.ReadLine();<br />
container.Insert(p1);<br />
<br />
}<br />
}<br />
}<br />
<br />
<br />
|
|
|
|
|
Tip: Use the pre tag when posting blocks of code. It makes it readable.
As far as I can see you only have overloads of the Insert method that takes an IComparable parameter. The Patient class doesn't implement the IComparable interface. Even if it would, the variable p1 is an IPatient reference, so it can never be used as an IComparable reference even if the actual ojbect would implement the IComparable interface.
Make the Patint class implement the IComparable interface, and change the variable p1 from an IPatient reference to a Patient reference.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
<pre>
//here is the IPatient implementation
using System;
using System.Collections;
public class Patient: IPatient, IComparable
{
private string fname;
public string FirstName
{
get
{
return fname;
}
set
{
fname = value;
}
}
public int CompareTo(Patient obj)
{
//Patient p1 = (Patient)obj;
return fname.CompareTo(p1.fname);
}
}
//the main method
using System;
using System.Collections;
namespace PatientName
{
class Program
{
static void Main(string[] args)
{
int choice;
Patient p1 = new Patient();
BSTree container = new BSTree();
Console.WriteLine("Enter the first Name of the patient:");
p1.FirstName = Console.ReadLine();
container.Insert(p1);
}
}
}
</pre>
|
|
|
|
|
The signature of CompareTo method will change like this
public int CompareTo(object obj){ You have to include a type checking of obj also
*jaans
|
|
|
|
|
And if i traverse the BST and try to output whats stored in BST it displays the Name of the ADT in my case "Patient" instead of the name of the people
|
|
|
|
|
You are using Console.WriteLine(root.Item); for output, but
root.Item<br /> is holding an IPatient object, so its displaying the type name itself.
If you want to display the FirstName cast the object and use the suitable properties.
*jaans
|
|
|
|
|
|
Modify your interface to implement IComparable interface
public interface IPatient:IComparable
{
string FirstName { get; set; }
} You may have to change your implementation of Patient class also accordingly.
*jaans
|
|
|
|
|
Yes i tried the solution you gave me earlier so i was wondering if i missed out something.
i get another error:
Doesnot implement interface member System.IComparable.CompareTo(Object);
|
|
|
|
|
see my comment to your earlier post.
*jaans
|
|
|
|
|
And if i traverse the BST and try to output whats stored in BST it displays the Name of the ADT in my case "Patient" instead of the name of the patient.
|
|
|
|
|
I have 3 doubts
1. I want to install DOTNET latest version in my computer. I dont have CD for installation. Which website would you suggest to get this done.
General Doubts
2. How to create
Internet and Show Desktop symbols on status bar
3. How to include
My Computer, My Documents , Network Neighbour symbols on desktop
|
|
|
|
|
What this has to do with c#?
Anyway the answers...
1. Microsoft download site
2. On status bar of what?
3. Use desktop properties
*jaans
|
|
|
|
|
1. Google.
2. Whose status bar?
3. TweakUI.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Hi,
In my web application i am using a text area. How to display the & as & < as < , is there any way rather than using string.replace??
Please suggest me, if possible give me some link where i can learn.
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
You can try
& amp for ampersand (without the space)
AND
& lt for less than (without the space)
A quick way to look these up is to get a blank web page (aspx extension), type the symbols you want in "design" view, switch to "source" view and copy/paste the generated code for the symbol.
For example I put the characters onto a webpage and switched to source and got:
<form id="form1" runat="server">
<div>
&<br />
<</div>
</form>
Hope this helps
Chris
p.s. next time, this might be better in the Asp.Net forum rather then the C# forum
[Edit: My careful formatting doesnt seem to have copied very nicely so modified the post!]
|
|
|
|
|
Thank you very much for spending your valuable time and helping me. But i am expecting a better solution
Know is Drop, Unknown is Ocean
|
|
|
|
|
You can always use HttpUtility.HtmlDecode to convert your HTML text back into normal text, however you really need to think about whether this is what you want to do. The whole point of HTML encoded text is to have something that will display in a web browser, so < is not the same as < - until the point you convert it using HtmlDecode.
|
|
|
|
|
Thank you very much for spending your valuable time and helping me.
Know is Drop, Unknown is Ocean
|
|
|
|
|
Dear all,
I'm trying to bind two ports to one IP address. In my first method I bind a port ( 31010 ) to IpAddress.Any
Int32 port = 31010;<br />
IPAddress localAddr = IPAddress.Any;<br />
server = new TcpListener(localAddr, port);<br />
server.ExclusiveAddressUse = false;<br />
server.Start();<br />
<br />
Byte[] bytes = new Byte[256];<br />
String data = null;<br />
<br />
while (true)<br />
{<br />
client = server.AcceptTcpClient();<br />
client.ExclusiveAddressUse = false;<br />
<br />
}</snip>
This works fine in itself. The application is listening on this port and receives data which is processed happily.
However, I add another method to bind another port ( 31009 ) which I call after the first one :
private static void SendMessageToMessenger(string data)<br />
{<br />
mm_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
<br />
IPAddress ip = IPAddress.Any;<br />
mm_socClient.ExclusiveAddressUse = false;<br />
int iPortNo = 31009;<br />
IPEndPoint ipEnd = new IPEndPoint(ip.Address, iPortNo);<br />
mm_socClient.Connect(ipEnd);<br />
<br />
Object objData = data;<br />
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());<br />
mm_socClient.Send(byData);<br />
<br />
<br />
mm_socClient.Disconnect(true);<br />
}
And then it goes wrong. It throws an Exception saying :
SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted
I know that the first method is performing a blocking call to receive data, but I'm assuming this blocking call is done for the port and not the IP address but I could be wrong there. Anyhow, it won't allow me to bind a different port to the same IP address, although I set the ExclusiveAddressUse to false .
Can anyone help me out here ?
Cheers,
|
|
|
|
|
I would try "netstat -a -o -n | more" before you start your application and check that the 31009 port isn't already open.
|
|
|
|
|
Hi
I need a NumericUpDown control in the ToolStrip. Anyone can help me out how to do this ?
Thx
|
|
|
|
|
Hi,
In order to add components to ToolStrip you need to embed the control in a ToolStripControlHost component and add that to the ToolStrip. You can either create a ToolStripControlHost instance then embed the control and then add the host to the ToolStrip, or you can derive your own class from ToolStripControlHost that creates its own NumericUpDown control. You'd go the first option if this is a one-off and the second if it's likely to be used again.
Hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|