|
I need to input a number through a textbox and display a message in my outbox that tells me whether or not there is an item in the data queue whose number matches that input.
My application is already able to initiate a data queue.
|
|
|
|
|
Ok - seems like you might be implimenting your own version of a Queue, which internally is using List<t>? In which case you would need to work out an algorithm for this...
Anyway, assuming you are using System.Collections.Generic.Queue<T> you can use the "Contains" method, for example:
Queue<string> q = new Queue<string>();
bool b = q.Contains("Hello world");
As for getting based on an ID number, Im not sure what you are wanting:
-If you want to do this like an index number (i.e. "Get the second item in the queue"), you can use an iterator (see foreach), or can cast it to an array (using ToArray) before getting the value.
-If each item in the Queue has a unique id number, which does not correspond to its index in the queue, you could try iterating until a condition is met
For example:
foreach(item x in queue)
{
if(x.Id == IdWeAreSearchingFor)
{
break;
}
}
Maybe one of these approaches will help you get a bit further, but if not let me know. It would be helpful to know if you are using Queue<t> or making your own Queue class based on List<t> if none of these suggestions helped!
Chris
|
|
|
|
|
I want to move a Panel from GroupBox1 to GroupBox2.
Please repair my code:
private void panel1_DragDrop(object sender, DragEventArgs e)
{
Panel a = (Panel)e.Data.GetData(typeof(Panel));
e.Effect = e.AllowedEffect;
a.Location = new Point(e.X, e.Y);
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
Panel p = (Panel)sender;
if (e.Button == MouseButtons.Left)
DoDragDrop(p, DragDropEffects.Copy);
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Panel)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
Thanks.
|
|
|
|
|
Hi all,
I'm working with the Aqua gauge control[^] that I found here on codeProject, which is a visual studio control, I believe.
What I want to do is show the property-grid control for the gauge and allow users to change the gauge's appearance and then ofcourse, save that new appearance. Aqua gauge works fine, property grid works fine, appearance changes, now I need to save the changes for nex time.
So - I was wondering - is there an easy way to save the gauge 'state', that is all values of its properties, easily ?
I mean, I can start programming and saving all gauge property values and loading them back in, or has Microsoft already thought of this, and created some easy method or something ?
Regards,
AYK
|
|
|
|
|
hi
serialize your properties with the XmlTextWriter to disk.
regards
|
|
|
|
|
Thanks! I'll look into this.
|
|
|
|
|
Hi all,
I'm developing a compiler like software so want to show the errors and warning of that software,
I want to use the "Error LIST" control that is used by Microsoft in Visual Studio.
Any one can tell me that what king of control it is? or how can i develop it.
Thanks
Syed Shahid Hussain
Syed Shahid Hussain
|
|
|
|
|
List view
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
more discussion please.
only a list view or with a form
and how it pop up????
thanks
Syed Shahid Hussain
|
|
|
|
|
ListView in a form, and it pops up in response to receiving event notifications, which suggests it's hooked up to the main application for compilation event notifications.
|
|
|
|
|
Thanks
But can u give me some example or similar article on my problem.
I'm waiting.
Really thanks.
Syed Shahid Hussain
|
|
|
|
|
So I have implemented the binary tree shown here (http://msdn.microsoft.com/en-us/library/ms379572.aspx[^]). I have no prior knowledge in I/O and its related areas, so any quick reads would be nice.
My question is, how would i save the tree (including the root as well as the internal and leaf nodes) into a file? How would i use the file after its saved? I have a decoder (just a simple program that traverses all of the tree's nodes and writes them out in console), but I would have no idea how to recall the file and decode it.
Any help is appreciated.
|
|
|
|
|
You might be able to use xml serialization to save and load the binary tree.
|
|
|
|
|
What I would do is firstly save the traversal. Pre / Post. And then the data. .Net makes IO easy. Try the StreamWriter and StreamReader classes
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
I want to be able to have the user select between two radio buttons. This will determine what page is loaded into a webbrowser object on part of the form. I even tried simple buttons, but the webbrowser only loads the first Url loaded. If button1 is selected first then only the url for button1 is loaded requardless of how many times button2 is pressed and etc for the other url. Is there something I need to set for the webBrowse object? This is annoying because it seems simple, but somehow isn't working.
modified on Friday, September 5, 2008 9:38 AM
|
|
|
|
|
Well I figured it out. Seems I had the AllowNavigation property set to false on the webBrowser control. silly me. Works now.
|
|
|
|
|
When you figure out the answer to a question that you post here, change the header of the original message to end with some variation of "SOLVED".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I'm creating a simple C# print class... this print class doesn't actually does the printing but more on layout and inserting objects into the page that is to be printed. You can insert objects in the page using the X-axis and Y-axis of the page.. No problems with that except that the Size and Height of the font is not relative to the X and Y axis cause i'm trying to insert a line break and i need the height of the text with the font used. How do I convert the height to something like Dots Per Inch?
|
|
|
|
|
hi
use the PrinterUnitConvert class in the System.Drawing.Printing namespace.
regards
|
|
|
|
|
Hi
I've added a crystal report in my project & added tables of my sql server database in that report. In the display section of the crystal report, I also added the column of the tables those i want to display in my report. Now, I am querying the database and binding the dataset to report but my reports always shows no records. I've checked my code by debugging & there are always 4 recods in the table of the dataset but my reports shows nothing. My code is here:
string query = "SELECT AccountBalanceLog.[Date], Company.CompanyName, Accounts.AccountNo, AccountBalanceLog.BalanceIn, AccountBalanceLog.BalanceOut FROM AccountBalanceLog INNER JOIN Accounts ON AccountBalanceLog.AccountNo = Accounts.AccountNo INNER JOIN Company ON Accounts.CompanyID = Company.CompanyID INNER JOIN Employee ON Accounts.EmployeeID = Employee.EmployeeID WHERE Employee.EmployeeID='1' AND Company.CompanyID='2' AND Accounts.AccountNo='Oanda1'";
SqlConnection Conn = new SqlConnection(MyConnectionString.ConnectionString);
SqlCommand myCommand = new SqlCommand(query, Conn);
Conn.Open();
SqlDataAdapter adp = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adp.Fill(ds);
ReportDocument doc = new ReportDocument();
string cwd = System.IO.Directory.GetCurrentDirectory();
if (cwd.EndsWith("\\bin\\Debug"))
{
cwd = cwd.Replace("\\bin\\Debug", "");
}
doc.FileName = cwd + "\\CrystalReport2.rpt";
doc.SetDataSource(ds);
crystalReportViewer1.ReportSource = doc;
Conn.Close();
please guide me where is am missing something.
thanks in advance...
Regards...
Mudasser Hassan
|
|
|
|
|
I'm using this code(see below)to import data from an excel spreadsheet into my database.now the problem is that it throws "Object reference not set to an instance of an object"exception whenever it gets to this line
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
what am i missing or what am i doing wrong? plz help
public void ImportToStudent()
{
try
{
//Gets the filename, not the path
string filename = ofd.SafeFileName;
string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\..\\PSAtechZTimetableSystem\\SpreadSheet.xls" + "; Extended Properties='Excel 8.0; IMEX=1; HDR=YES'";
// Here is the call to Open a Workbook in Excel
// It uses most of the default values (except for the read-only which we set to true)
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
using (SqlConnection conPSAtechZ = new SqlConnection(connection))
{
conPSAtechZ.ConnectionString = connection;
using (SqlCommand commandExcel = conPSAtechZ.CreateCommand())
{
System.Data.DataTable table = new System.Data.DataTable();
commandExcel.CommandText = "SELECT [StudentID] AS [StudentID]," + "[ModuleCode] AS [ModuleCode], " + "FROM [Sheet1$]";
//Open the Excel Connection
conPSAtechZ.Open();
using (SqlDataReader dr = commandExcel.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read() && dr.HasRows)
{
lblResults.Text = "Importing...";
try
{
studentdal.RegisterStudents(new RegisterStudent(Convert.ToString(dr["StudentID"]), Convert.ToString(dr["ModuleCode"])));
commandExcel.CommandType = CommandType.StoredProcedure;
lblResults.Text = "Successfully Imported!!";
}
catch (Exception Ex)
{
MessageBox.Show("Error!!\n " + Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
dr.Close();
}
}
}
}
catch (Exception EX)
{
MessageBox.Show("The spreadsheet is not in the correct format!\n\n" + EX.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
|
|
|
|
|
Twyce wrote: I'm using this code(see below)to import data from an excel spreadsheet into my database.now the problem is that it throws "Object reference not set to an instance of an object"exception whenever it gets to this line
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t",
false, false, 0, true, true, true);
what am i missing or what am i doing wrong? plz help
It means that one of the objects you're trying to access is null . Start your application in the debugger, step into this line (it'll automatically when throwing the exception) and see which of them is null.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
It's likely the variable ofd is null when you reach the error line.
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
You posted "twyce"
|
|
|
|
|
I'm using this code(see below)to import data from an excel spreadsheet into my database.now the problem is that it throws "Object reference not set to an instance of an object"exception whenever it gets to this line
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
what am i missing or what am i doing wrong? plz help
public void ImportToStudent()
{
try
{
//Gets the filename, not the path
string filename = ofd.SafeFileName;
string connection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\..\\PSAtechZTimetableSystem\\SpreadSheet.xls" + "; Extended Properties='Excel 8.0; IMEX=1; HDR=YES'";
// Here is the call to Open a Workbook in Excel
// It uses most of the default values (except for the read-only which we set to true)
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t", false, false, 0, true, true, true);
// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
using (SqlConnection conPSAtechZ = new SqlConnection(connection))
{
conPSAtechZ.ConnectionString = connection;
using (SqlCommand commandExcel = conPSAtechZ.CreateCommand())
{
System.Data.DataTable table = new System.Data.DataTable();
commandExcel.CommandText = "SELECT [StudentID] AS [StudentID]," + "[ModuleCode] AS [ModuleCode], " + "FROM [Sheet1$]";
//Open the Excel Connection
conPSAtechZ.Open();
using (SqlDataReader dr = commandExcel.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read() && dr.HasRows)
{
lblResults.Text = "Importing...";
try
{
studentdal.RegisterStudents(new RegisterStudent(Convert.ToString(dr["StudentID"]), Convert.ToString(dr["ModuleCode"])));
commandExcel.CommandType = CommandType.StoredProcedure;
lblResults.Text = "Successfully Imported!!";
}
catch (Exception Ex)
{
MessageBox.Show("Error!!\n " + Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
dr.Close();
}
}
}
}
catch (Exception EX)
{
MessageBox.Show("The spreadsheet is not in the correct format!\n\n" + EX.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
|
|
|
|
|