|
Sample c#
<br />
private void ACCombo_KeyUp(ComboBox cbo, KeyEventArgs e)<br />
{<br />
switch(e.KeyCode)<br />
{<br />
case Keys.Back:<br />
case Keys.Left:<br />
case Keys.Right:<br />
case Keys.Up:<br />
case Keys.Delete:<br />
case Keys.Down:<br />
return;<br />
}<br />
<br />
string strTypedText = cbo.Text;<br />
int intFoundIdx = cbo.FindString(strTypedText);<br />
<br />
if(intFoundIdx >= 0)<br />
{<br />
object objFoundItem = cbo.Items[intFoundIdx];<br />
<br />
string strFoundText = cbo.GetItemText(objFoundItem);<br />
<br />
string strAppendText = strFoundText.Substring(strTypedText.Length);<br />
cbo.Text = strTypedText + strAppendText;<br />
<br />
cbo.SelectionStart = strTypedText.Length;<br />
cbo.SelectionLength = strAppendText.Length;<br />
}<br />
}<br />
<br />
private void ACCombo_Leave(ComboBox cbo)<br />
{<br />
int intFoundIdx = cbo.FindStringExact(cbo.Text);<br />
cbo.SelectedIndex = intFoundIdx;<br />
}<br />
Let me know if you need this for VB.NET
I reject to reality and subsitute my own!
- Adam Savage, Mythbuster
life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
|
|
|
|
|
Thank you so much jklucker
exactly what i wanted
|
|
|
|
|
how to bind a richtextbox control's rtf property to the database??
I convert it to byte array and pass it on in a stream as a byte array and then call
Loadfile method of RichTextBox and pass the stream.
but it says that the specified file is not in a correct format
can u please suggest
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
namespace deleteit1
{
public class richtextbox : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox2;
private deleteit1.Dataset1 dataset11;
private System.Windows.Forms.ComboBox comboBox1;
private System.ComponentModel.IContainer components;
public richtextbox()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application.Run(new richtextbox());
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.dataset11 = new deleteit1.Dataset1();
this.comboBox1 = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.dataset11)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(552, 368);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox2
//
this.richTextBox2.Location = new System.Drawing.Point(16, 8);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(624, 336);
this.richTextBox2.TabIndex = 2;
this.richTextBox2.Text = "richTextBox2";
this.richTextBox2.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
//
// dataset11
//
this.dataset11.DataSetName = "Dataset1";
this.dataset11.Locale = new System.Globalization.CultureInfo("en-US");
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(32, 368);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(320, 21);
this.comboBox1.Sorted = true;
this.comboBox1.TabIndex = 3;
this.comboBox1.Text = "comboBox1";
//
// richtextbox
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 430);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.richTextBox2);
this.Controls.Add(this.button1);
this.Name = "richtextbox";
this.Text = "richtextbox";
this.Load += new System.EventHandler(this.richtextbox_Load);
((System.ComponentModel.ISupportInitialize)(this.dataset11)).EndInit();
this.ResumeLayout(false);
}
#endregion
SqlConnection con = new SqlConnection();
private void richtextbox_Load(object sender, System.EventArgs e)
{
con.ConnectionString = @"data source = DEVELOPMENT;user id = SHC;password = SHC;initial catalog = SHC";
if(con.State == 0)
{
con.Open();
}
try
{
string st;
st = "select * from deleteit";
SqlDataAdapter ad = new SqlDataAdapter(st,con);
ad.Fill(dataset11,0,0,"deleteit");
char[] chardata = new char[1000];
DataTable dt = dataset11.Tables[0];
ArrayList arr = new ArrayList();
//byte[] binaryData = new byte[1000];
//Encoder e1 = Encoding.UTF8.GetEncoder();
Encoding encode = Encoding.UTF8;
if(dt.Rows.Count>0)
{
foreach(DataRow row in dt.Rows)
{
// Convert the string into a byte[].
byte[] binaryData = encode.GetBytes(row["rtf"].ToString());
comboBox1.Items.Add(row["rtf"]);
comboBox1.SelectedIndex = 0;
//MessageBox.Show("binary data length = "+binaryData.Length.ToString());
arr.AddRange(binaryData);
}
}
else
{
MessageBox.Show("no rows");
}
byte[] bytearr = new byte[arr.Count];
arr.CopyTo(bytearr);
MessageBox.Show("byte array copied from arraylist="+ bytearr.GetType());
ASCIIEncoding encoding = new ASCIIEncoding();
richTextBox2.Rtf = encoding.GetString(bytearr);//,0,bytearr.Length);
System.IO.MemoryStream stream = new System.IO.MemoryStream((byte[])bytearr);
richTextBox2.LoadFile(stream,RichTextBoxStreamType.RichText);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
}
}
}
}
table name->deleteit
fields-->rollno(numeric),rtf(text)
|
|
|
|
|
I want to create an Archive Mail Reader in C#. With this one can view their mails. No options for editing, deleting or forwarding will be there. Can anyone give an idea about how it can be implemented using C#.
|
|
|
|
|
I have a javascript that creates a dynamic drop down with a person's name as the name is typed. Once the user clicks on the name from the dropdown the page reloads with that person's information in the pages web control's. This part works wonderfully. What doesn't work is when I try to manually edit the text boxes with new values. When I click on my Edit button the text boxes pick up on the intial values and not the new values that were put in the text box. Any ideas why?
|
|
|
|
|
Make sure you don't rebind the data on postback:
Page_Load:<br />
<br />
if(!IsPostBack){<br />
BindData();<br />
}
if you rebind the data here, your changed values will not appear
|
|
|
|
|
I'm trying to get these two methods to modify a value stored within the namespace Interface_Resources and the class TrafficCalculations. I am trying to get them to call two new methods called TrafficLimitIncrement (for UpButton) and TrafficLimitDecrement (for DownButton). How can I do this? I'm in a mental block atm and it's driving me nuts!
Cheers for any help.
[edit]I should probably mention that the Interface_Resources is a dll file being used by a form (which is using the methods UpButton and DownButton) to change a value.[/edit]
|
|
|
|
|
|
hii all .
i need to browse the web from a windows application , just like web application .
using link control or button how can i navigate to a web site or emailing and contacting some on .
thanx alot
لا اله الا الله محمد رسول الله
|
|
|
|
|
Use shellexecute. Or, I believe there's a static 'Process' class kicking around in the runtime that lets you do the same thing without interop.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You could try adding a WebBrowser control on ur Windows' form. It will give u all the necessary functions for simulating a Web Browser, along with its behaviour.
Hope this helps
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
I have a propertygrid, I set its property SelectedObject to the object I want. It displays all the properties. Is there a way to make it display only the properties I want? And how to apply the chenges after the user clicks, let's say Apply button?
|
|
|
|
|
You need to apply attributes to your properties,
I beleive the attribute: BrowsableAttribute will determine whether it gets displayed or not.
As for applying the changes, I assume you have both get and set'ers in your code?
|
|
|
|
|
Is there a way to make it display only the properties I want?
You'll need to implement ICustomTypeDescriptor and return the properties you want displayed in the GetProperties method. These articles (Customized display of collection data in a PropertyGrid[^], Globalized property grid[^], Bending the .NET PropertyGrid to Your Will[^]) show how to do this.
And how to apply the chenges after the user clicks, let's say Apply button?
The best way would probably be to create a new class that contains the properties to be displayed and also implements ICustomTypeDescriptor which you can then select into the property grid instead of the other class. Then when the Apply button is clicked you can copy the new values back.
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
Could you give me the simplest example how to do it? I can't cope with it, I'm new to C#
|
|
|
|
|
My outlook bar contains number of icons and names for those each icon. If Iright click my mouse button then I can rename the text in the icon name. I want to disable this option. Any ideas?
rajitha_kba
|
|
|
|
|
Is this siutable for C# ?
|
|
|
|
|
Ok i am re-asking the question ,probably i wasn`t clear enough to get the attention of people like Heath Stewart
i am working on a add-on Application which would be crawler like,means there would be an entry point URL(e.g: http://site.com/virtual/index.asp),the links from the page will be retrieved and then same process will be repeated with those links,during this exercise,i found relative link on a webpage,for instance "members/file.asp" etc
sine in next round,i have to access the above mentioned URL via HTTPWEbrequest,for that i would have to pass url something like http://site.com/virtual/members/file.asp,where bold part is the part has to be attached with the resultant Url,in html,web browser can understand relative paths, for instance,browser will convert the relative url "../my.asp" to http://site.com/my.asp when its rendered on browser,how could it be done if its done on a non web based application in C#
Thanks
MyBlogs
http://weblogs.com.pk/kadnan
|
|
|
|
|
|
I've got some long-running operation that could be cancelled by the user. The way I'm doing it is
1. launch a second thread to do the entire operation.
2. when the second thread comes to the long-running piece of the operation, it launches a 3rd thread
3. the second thread monitors the 3rd thread, waiting for it to complete, while also monitoring if the user has cancelled.
My code looks something similar to
void DoHeavy()
{
EatCpuForTwoMinutes();
}
void DoEntireOperation(ICancellable cancelFlag)
{
...
ThreadStart heavyMethod = new ThreadStart(DoHeavy);
IAsyncResult result = heavyMethod.BeginInvoke(null, null);
while(result.IsCompleted == false)
{
if(cancelFlag.IsCancelPending) break;
else Thread.Sleep(250);
}
...
}
I feel like Thread.Sleep is a total waste, since the operation could complete before 250 milliseconds is up. I also feel this is inducing too much overhead, constantly checking whether the delegate is completed. Is there a better way to do this?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
But do you actually kill the DoHeavy thread? Is there someplace that the DoHeavy thread can check to see whether it should cancel itself? That's usually the best practice.
As it is now, it looks like you are allowing the second thread to exit, but DoHeavy will continue running, eating up CPU cycles until it's done. This is probably not ideal.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
I don't kill the DoHeavy thread because DoHeavy is calling a method in a library I don't have the source code for (so I can't 'cancel' the thread, so to speak). And I'm a firm believer in abstaining from Thread.Abort calls, especially from asynchronous code.
The slow method in question is actually a synchronous IO operation, one which the library providers did not provide an asynchronous alternative to, so in reality it's not so much eating the CPU cycles as it is just wasting disk space on an disk writing operation.
As far as the Thread.Sleep() & operation.IsCompleted calls inside the while loop, is there any better way to do that? If not, would it be wise to make shorter iterations in the sleep loop (causing more IsCompleted calls) or better to sleep more and query IsCompleted less often?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
This really brings up a question i have in mind, which I've tried but with no success. Assume the following:-
<br />
Thread _thread = new ThreadStart(SomeMethod)<br />
public void SomeMethod()<br />
{<br />
}<br />
The aboved code is ok.
But, if I wanted to do this,
<br />
Thread _thread = new ThreadStart(SomeMethod)<br />
public void SomeMethod(int a, int b)<br />
{<br />
}<br />
It will complain, because the delegate does NOT take any callback functions with parameters. Question, is there a way to achieve what I'm trying to do ?
Provide sample syntax if got possible solution(s).
Thanks
Stanley
|
|
|
|
|
Yes, but not with Thread.Start (although you can in .NET 2.0, because Thread.Start will have overloads to take a ParameterizedThreadStart, which allows you to pass a System.Object parameter).
For .NET 1.x code, you have 2 options.
You could use the built-in .NET threadpool:
void SomeMethod(object parameter)
{
int[] typedParam = (int[])parameter;
}
WaitCallback waitCallback = new WaitCallback(SomeMethod);
ThreadPool.QueueUserWorkItem(waitCallback, new int[]{1, 5});
Or you can define your own delegate (or use an existing one) that matches your desired method signature (i.e. has the correct number of parameters and the correct parameter types), then call delegate.BeginInvoke on it:
delegate void MethodWithTwoIntegers(int a, int b);
void SomeMethod(int a, int b)
{
}
MethodWithTwoIntegers myMethod = new MethodWithTwoIntegers(SomeMethod);
myMethod.BeginInvoke(5, 10, null, null);
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
|