|
Not sure I got your question. Please post relevant code so that we understand what you are saying.
|
|
|
|
|
Thanks Navaneeth,
Here is an example of what I am trying to do:
// Entry Point:
DummyForm.TestsFinished += new EventHandler(DummyForm_TestsFinished);
// Start Processing the query
// viewFrameworkDummyForm.ProcessQueryInstructions(queryInstructions);
// Start the Application message pump (the viewFx has to be run on a form to be contained within a thread UI)
DummyForm myForm;
// ****************************************
// I get a Cannot access disposed object ex on this below line:
// ****************************************
Application.Run(myForm = new DummyForm(queryInstructions));
// DummyForm:
public partial class ViewFrameworkDummyForm : Form
{
private List<QueryInstruction> queryInstructions;
public static event EventHandler TestsFinished;
/// <summary>
/// Constructor
/// <summary>
void DummyForm(List<QueryInstructions>queryInstructions)
{
…
// Does stuff with query instructions…
…
// Event gets fired somewhere in the constructor…
OnQueryInstructionsProcessed(this,new EventArgs());
…
}
// Notifies the attached events to QueryInstructionsProcessed, that the query instructions have been processed.
void OnQueryInstructionsProcessed(object sender, EventArgs e)
{
//Inform that the tests have been finished, and then close the form..
TestsFinished(this, new EventArgs());
this.Close();
Application.Exit();
}
}
|
|
|
|
|
i wanna pull multiple records in from a database and display them in different labels
I was thinking of returning them in an array then adding them to the specified labels, can anyone point me to the an example or aid me.
sample code
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=BABOO;uid=sa;password=sa;database=quiz");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
string query;
query = "select QuestionText,AnswerA,AnswerB,AnswerC,AnswerD from quest where QuestionID='1'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
nt rbCount = Convert.ToInt32(TextBox2.Text);
RadioButton[] radioButtons = new RadioButton[rbCount];
for (int i = 0; i < rbCount; ++i)
{
radioButtons[i] = new RadioButton();
radioButtons[i].Text = dr.GetValue(1).ToString();
}
Please i need your help
Ferron
|
|
|
|
|
So, this seems a little retarded to me.
1 - you want to have a textbox showing how many answers to show ? So, what if the right answer gets hidden ?
2 - how do you make sure that textbox2 contains a number ?
3 - why don't your variables have real names ?
4 - You're reading the same value from the answer list every time
5 - you never add the radio buttons to your UI
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
i know, that's why i need your help to sort it out the write way. basically what i have is 3 textbox
text[1]
text[2]
text[3]
if three records are in the database it should bring back three sets of record all in their respective textbox.
Plz can u help
Ferron
|
|
|
|
|
So the possible answers go in textboxes, not in radio buttons ?
Are you saying the number of answers is flexible ? I would do this with a data bound control, assuming I had to show more than one question on a page.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yes I want to show the results in the text box? I have it created in a form. Is the the data bound control flexible? Can the realit be formatted in a form like manner, for say a application form?
Ferron
|
|
|
|
|
Yeah, you can define a template for a data bound control and show the data any way you like.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I have used a form view, its working well, the thing is how do I get it to display records one under the other instead of paging?
Ferron
|
|
|
|
|
I used a data list control to display all my records, but i have been trying to add paging capability.
Ferron
|
|
|
|
|
I am trying to write some code that will read the contents of a file (C:\Temp\index.html) and replace any smart quotes (“ and ”) with neutral quotes ("). I can find the quotes if I open the file with 1252 encoding, but the replacement does not work. Also, the quotes are found even though they are showing found as values of hex 201C and 201D even though the smart quotes are hex 93 and 94 if I open the file in a hex editor .
using System;
using System.Text;
using System.IO;
namespace EncodingExample
{
class Program
{
static int CharPositions(string data, char[] chars)
{
int count = 0;
int pos = data.IndexOfAny(chars);
while (pos > -1)
{
count++;
Console.WriteLine(" Position: {0}", String.Format("{0:X}", pos));
pos = data.IndexOfAny(chars, pos + 1);
}
return (count);
}
static void Main()
{
string srcFile = @"C:\Temp\bosssystems\index.html";
if (File.Exists(srcFile))
{
char[] chars = { '"', '"' };
char quote = '"';
string data = File.ReadAllText(srcFile, Encoding.GetEncoding(1252));
Console.WriteLine("Before Replacement");
CharPositions(data, chars);
Console.WriteLine();
foreach (char c in chars)
{
data.Replace(c, quote);
Console.WriteLine("Replacing {0}({1}) for {2}({3})", c, String.Format("{0:X}", (int)c), quote, String.Format("{0:X}", (int)quote));
}
Console.WriteLine();
Console.WriteLine("After Replacement");
CharPositions(data, chars);
Console.ReadKey();
}
}
}
}
|
|
|
|
|
When you load the file, the byte codes 0x93 and 0x94 are decoded into the unicode characters with character codes 0x201C and 0x201D.
Does the compiler support unicode in the source code? I would write the characters using escape codes so that I was sure that I got the correct characters:
char[] chars = { '\u201C', '\u201D' };
The replace is probably working just fine, but you are throwing away the result. The Replace method returns the result, and you have to assign it to something, like assigning it to the string variable where you had the input:
data = data.Replace(c, quote);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello again,
I'm wondering, is there a way to have an event set up so that if a registry key is created, accessed or modified in much the same way a FileWatcher works?
Thanks,
Michael Fritzius
|
|
|
|
|
I don't believe so.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
See: http://www.codeproject.com/KB/system/registrymonitor.aspx[^]
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
|
hi,
I'm trying to write a simmple phonebook program in C#,that users can enter name,surname,Email adrs & phone number(I defined a class that has got these elements).this program can also do the searching by Hashtable with the Email key.these information are saved in a text file.but whenever I try to open the text file,the file opens,but I can't do the searching over the items of the list!!the question is how can I get access to the elements of an item?I guess I should define the opened file type,but I don't know how!!so if there is anybody that can help me,I would really appreciate that.tnx
|
|
|
|
|
Hi,
it is not completely clear what your problem is. Some facts for you:
1.
if you have a class Person holding all info regarding a person, then add instances of that class to the listbox (yes a listbox can hold items, not only strings; when they are not strings you must help it in displaying the items though, either by providing your own ToString method, or better yet by performing the painting yourself, i.e. DrawMode=OwnerDraw).
2.
if all info is in memory, it should be easy to find a specific person; Find could be a method inside the Person class, scanning all the existing Person objects (keep a static List of them in the class)
and return one Person, or a List< Person> when one or more matches are found.
3.
if all your persons info is in memory, there is no need to keep a file open at all. You could read the file once to populate the person objects and add them to the listbox, then keep the file closed; when you decide some changes in memory need to be saved to the file, just dump the current person info from memory to the file, overwriting everything that is there (for starters use a different filename, e.g. append current time as HHMMSS so you don't loose it all by mistake).
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:26 PM
|
|
|
|
|
hi,
first of all tnx for your consideration.
yes I have a class called person.see,I don't have problem with saving and opening a text file & showing it in a list box.the problem is when I save a text file and close the program (stop it running)
and then run it again and click the Open button it opens the text file,and shows it in the list box,but can't do any searching over the opened file!!!
this is the search code:
private void btnSearch_Click(object sender, EventArgs e)
{
//objPersonArraylist is a hashtable object
if (objPersonArraylist.Contains(txtEmail.Text.ToLower()) == true)
{
//person is my class
MessageBox.Show("The person is :" + ((Person)objPersonArraylist[txtEmail.Text.ToLower()]).FullName, "Found!");
}
else
{
MessageBox.Show("No such person exist in the list!", "Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
and this is the Open file code:
private void btnOpen_Click(object sender, EventArgs e)
{
string at="@";
openFileDialog1.Title = "Open A Text File";
openFileDialog1.Filter = "Text File(*.txt)|*.txt|All Files(*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.InitialDirectory = "C:\\Users\\Golputer\\Documents";
openFileDialog1.DefaultExt = "txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = openFileDialog1.FileName;
try
{
lstOfNames.Items.Add(System.IO.File.ReadAllText(strFileName));
int what = lstOfNames.FindString(at,-1);
if (what != -1)
{
lstOfNames.SetSelected(what, true);
MessageBox.Show("that's it,found!");
}
else
{
MessageBox.Show("Sorry,item is not here");
}
}
catch
{
MessageBox.Show("Sorry,can't open the file!");
}
}
}
|
|
|
|
|
Hi,
please next time use the "code block" button to publish code, that way you get PRE tags which
provide a background and a monospaced font, and preserve formatting; all this makes it a lot
easier to read and help you.
Nevertheless there are two major errors I could spot:
1.
you are using File.ReadAllText() which returns a single string, hence your listbox contains only one item.
2.
you are using ListBox.Find(string str) which searches for an item STARTING with str, probably
not finding anything (because you only have one item, and it probably does not start with @)
You will need some more code to get your app to do what you want...
BTW: I advise against MessageBox for tracing what is going on, because you can see only one at a
time, once closed they are gone forever, and they soon become very annoying. I recommend you use
Console.WriteLine() instead. That creates a trace log in the output pane of Visual Studio, and does
not stop your thread.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:26 PM
|
|
|
|
|
hi there again.
I guess the first error you spoted is right,I'm using File.ReadAllText() which returns a single string,hence my listbox contains only one item.what should I do to make it not just one item?I mean it reads the text file and returns one item,instead of the several items that there are!!
|
|
|
|
|
Hi,
I am not going to hold your hand and spoon feed you.
There is a lot of documentation available that gives you all the details of the available classes and methods; whatever way you got hold of ReadAllText() is likely to also contain the right methods for your needs.
And if you are new to programming, to .NET or to C# the one and only right way to get started is by buying and studying a book on the subject. That way you get the overall picture, all the basic terminology and information, as well as a lot of examples; all this in a much shorter time than it would take you in any other way.
BTW I do not recommend any particular book, go to the bookstore, look at some, and pick one or two that look promising.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:27 PM
|
|
|
|
|
hi.
tnx for your help.I had searched and read 2 E-books and did'nt find what I was looking for.I studied one,was'nt there either.searched MSDN found something helpful,but not exactly though.I guess I should change the method of my researching.
but thank you,you did help me.
|
|
|
|
|
I recommend you buy and study a real book; downloading and browsing an ebook is no substitute.
Electronic information is fine as reference material, but introductions and tutorials better be
actual books you can read at your leisure; they do cost a few dollars/euros but are worth what you pay for them.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:27 PM
|
|
|
|
|
hi.
well in that case what book do you suggest?would Christian Nagel's be fine?or Andrew Stellman & Jennifer Greene's?I've heard so much about Christian Nagel complete refrence!!is that worthy?
|
|
|
|
|