|
yep.
just use a for(int i=0;i
|
|
|
|
|
here is what I've come up with so far. 208 nodes get put into the array i checked that in the debugger but i get an exception each time it finds a instance where the node is the same. in example
says can not add or insert the item 'tbone,eater' in more than one place.
here is what i'm using in my main form
private void Filter_combo_SelectedIndexChanged(object sender, EventArgs e)
{
string filter = Filter_combo.Text;
using (var db = new mombooksDataContext(Properties.Settings.Default.BooksConnectionString2))
{
TreeNodeCollection[] nodes = new TreeNodeCollection[treeView1.Nodes.Count];
treeView1.Nodes.CopyTo(nodes, 0);
treeView1.Nodes.Clear();
treeView1.Nodes.AddRange(NodeBuilder.BuildNodes(treeView1.Nodes, db.Authors, db.Books, filter));
}
}
then i'm calling the modified class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using momdb;
namespace Utilties
{
public sealed class NodeBuilder
{
public static TreeNode[] BuildNodes(TreeNodeCollection nodes,IEnumerable<Author>authors,IEnumerable<Book>books,string filter)
{
TreeNode node = new TreeNode();
if (filter == "Keywords")
{
node = nodes.Add("Keywords");
books.ToList().ForEach(m =>
{
node.Nodes.Add(m.Keywords);
node.Tag = filter;
});
}
if (filter == "Title")
{
node = nodes.Add("Title");
books.ToList().ForEach(m =>
{
node.Nodes.Add(m.Title);
node.Tag = filter;
});
}
if (filter =="Author")
{
node = nodes.Add("Authors");
authors = authors.ToList().Distinct();
authors.ToList().ForEach(m =>
{
node.Nodes.Add(string.Format("{0},{1}",m.AuthorFirst,m.AuthorLast));
node.Tag=filter;
});
}
TreeNode[] holder = new TreeNode[node.Nodes.Count];
for (int i = 0; i < node.Nodes.Count; i++)
{
holder[i] = node.Nodes[i];
}
return holder;
}
}
}
still confused
|
|
|
|
|
I don't know exactly and right know I don't have the time to try it and see what is wrong.
I mean the message is clear => something with duplicate items.
You could try to return the Tree nodes collection and of course edit the method to return a Collection
not array. See if it helps
|
|
|
|
|
I figured it out thanks for your time...
|
|
|
|
|
i have two collections defined below
List<ScienceStudents> lstScienceStudents = GetScienceStudentCollection();
List<MathsStudents> lstMathsStudents = GetMathsStudentCollection();
Now both the classes ScienceStudents and MathsStudents have a common id Student_Id.
I need to set the boolean property IsMathStudent in lstScienceStudents to true by joining the two collection.
To be more clear here is the code
for (int i = 0; i < lstScienceStudents .Count; i++)
{
for (int j = 0; j < lstMathsStudents.Count; j++)
{
if (lstScienceStudents[i].Student_Id == lstMathsStudents[j].Student_Id)
lstScienceStudents[i].IsMathStudent = true;
}
}
I know i can get the collection of MathsStudents in ScienceStudent collection using join in linq. But i need to set the flag to true in the lstScienceStudent collection list.
How can i do it?
|
|
|
|
|
You can't modify a field during a Linq query. But, you can return a new IEnuerable(T) or List(T)
Something like this:
var needed = from sRec in lstScienceStudents
from mRec in lstMathsStudents
where sRec.Student_Id.Equals(mRec.Student_Id)
select new{
Field1here = YouKnowWhat;
Field2here = YouKnowWhat;
}
|
|
|
|
|
Hi everyone,
I have a minor problem with one of my assignments. I want my child form to show defalut values on open. When i update the data or change the existing data i want it to be saved and then when i reopen the form i want those values to be shown. To elaborate more, I have a parent form and child form. When i select an item from a combo box in parent form and click on update button, the child form opens and shows default values. And then when i change the default values and click the update button in the child form the values need to be changed. So when i close the child form and reselect the same product and click update from parent form. The new values need to be shown. I am attaching a link to my code. Please take a look
http://nexusfactor.webs.com/LabAssignment3.rar
|
|
|
|
|
Nobody is going to download your code. You can paste your code here (at least, the relevant bits). What is your question? What are you having a problem with?
Pass the values into the child form via the constructor. Return the result when the child form closes by storing them to a public property of the child form. The parent form can then access that property after the child form closes and save that value for later (e.g., when passing it again to the constructor of the child form).
Is that the answer you were looking for, or did you have a more specific problem?
|
|
|
|
|
in my parent form i created an array string with values. i passed that array to the child form's constructor. then i created instance array in the child form and i set that equal to the array passed from the constructor so i can use it. i used it to display the passed string value in my combo box. i also created a public string variable. then on button click i set the public string variable equal to the newly selected item from combo box. i go back to my parent form and my code looks something like this:
private void updateProductInfo_Click(object sender, EventArgs e)
{
productStatus = false;
ProductForm pFTwo = new ProductForm(this, category);
pFTwo.Show();
if (pFTwo.updateStatus == true)
{
category[pFTwo.aProductCategoryIndex] = pFTwo.aProductCategory;
}
}
as u can see my public variables from my child form is "aProductCategory". but nothing is happening when i reopen my child form. the combo box value is still the same
|
|
|
|
|
You are using a local variable for your ProductForm so every time you go through the updateProductInfo_Click() method you start a new form. Create your child form in your main form intialisation and use that throughout your code.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
|
Set the data how you would like in your child's form load event.
|
|
|
|
|
|
Dear frd's
I have a problem in reading data from parallel port. There is a serial port control available which will work with serial port in asp.net and c# but i never find any parallel port related class. Then I was using "inpout32.dll" third party DLL which is giving two methods Inp32 and Out32 by which we can read or write to parallel port.
But unlike serial port there is no data received event available in this dll. Is there any way available to get the data when ever parallel port receives some data.
Thanks for you time and consideration.Thanks & Regards,
Anil Chelasani
|
|
|
|
|
I'm wanting to add all the values i get from my for statements into a list of type string. I tried the following but i get a casting error
List<string> str = new List<string>();
int rCount = 0;
int cCount = 0;
range = xlWorkSheet.UsedRange;
for (rCount = 1; rCount <= range.Rows.Count; rCount++)
{
for (cCount = 1; cCount <= range.Columns.Count; cCount++)
{
str = (List<string>)(range.Cells[rCount, cCount] as Excel.Range).Value2;
}
}
one day I hope to not be the one asking the questions but the one answering them. Until then please forgive me for my basic questions
|
|
|
|
|
Replace it with something like this:
for(rCount...){
for(cCount...){
str.Add(range.Cells[rCount, cCount].Value2.ToString());
}
}
|
|
|
|
|
ahh thank you very much...
|
|
|
|
|
|
Hey one last thing if you have the time... What I'm trying to do using an example of course. is read my excel sheet columns a,b,c,d,e one row at a time into a list so I can take those values and hopefully insert them into a database. I have the database insert method working fine I just need to figure out how to get the data into a format so I can pass it to the stored procedure I made.
I'm aiming to get index[0].text index[1].text and so forth for each row... What I have so far gets the values of each row but one column at a time so lets say I have tony smith testing somethingelse 1.99
i get the following results
[0] tony
[1] smith
[2] testing
[3] somethingelse
[4] 1.99
what I'd like to do is label the results if all possible like first = [0], last =[0]
that way when i wanted to use the data i could simply do something like this
row.first
row.last
row.whatever
here is the code i have those for but I'm confused how to accomplish what i'm trying to do
private void importDataFromExcelToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenExcelFile.Title = "SELECT EXCEL FILE TO IMPORT FROM ";
OpenExcelFile.Filter = "XLS FILES|*.XLS";
OpenExcelFile.InitialDirectory = @"c:\";
string filepath = null;
if (OpenExcelFile.ShowDialog() == DialogResult.OK)
{
filepath = OpenExcelFile.FileName;
}
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(filepath, 0, true, 5, "", "", true,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t",
false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
List<string> strList= new List<string>();
string str;
int rCount = 0;
int cCount = 0;
range = xlWorkSheet.UsedRange;
for (rCount = 1; rCount <= range.Rows.Count; rCount++)
{
for (cCount = 1; cCount <= range.Columns.Count; cCount++)
{
str = (string)(range.Cells[rCount, cCount] as Excel.Range).Value2;
strList.Add(str);
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Unable to release the Object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
|
|
|
|
|
Hy,
It's all wrong.
1)Create a class like
public class Something{
public string Name{get;set;}
public string Surname{get;set;}
.
.
.
}
And then create a List<Something> instead of list of string(s);
2) When loading data if you keep loading it using Interop create something like:
for(RCount...{
curr = new Something();
for(cCount...){
if(c==1){
curr.Name = (string)(range.Cells[rCount, cCount] as Excel.Range).Value2;
}
if(c==2){
...
}
.
.
}
lst.Add(curr);
}
But I Really don't recomend this approach.
Use something like this. It's a lot faster and it does not require Excel to be installed
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + yourFileNameHere+ ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\";";
OleDbConnection con = null;
lst = new List<Something>();
Something curr = new Something();
con = new OleDbConnection(connString);
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Name,SurName,etc.. " +
"FROM [Sheet1$]";
OleDbDataReader dr = null;
try
{
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
curr = new Something();
curr.Name = dr.IsDBNull(0) ? "Empty" : dr.GetString(0);
curr.SurName = dr.IsDBNull(1) ? "Empty" : dr.GetString(1);
.
.
if (curr.IsOK())
{
lst.Add(curr);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con.State != ConnectionState.Closed)
{
con.Close();
}
con.Dispose();
con = null;
}
and a create a method inside your class(Something) in this silly example of mine that returns true if the current Something is OK, else false.
Usefull in order to avoid filing your list with "Empty"/Nok rows.
[EDIT] And now you could use LINQ to get the datas something like:
var needed = from rec in lst
where rec.Name=="YourName"
select whateverYouNeed;
modified on Thursday, February 18, 2010 1:02 AM
|
|
|
|
|
WOW!!!! Thanks I didn't expect you to go through all this trouble but I really appreciate it. As you can tell I'm learning and trying. Honestly hate asking so many questions but I guess that is the only way to learn.
Once again I totally appreciate your time.
|
|
|
|
|
One again you're welcome.
But it didn't took me much time as I have some small "inhouse aaps/tricks" to load all kind of
excel data to the DBs and vice versa. So I just copy and paste, renamed the columns/fields deleted
logic and that's all.
|
|
|
|
|
You ever have the problem of copying stuff from access into an excel spreadsheet. and for whatever reason
the code you posted does not read it? It keeps on tripping up on the getstring().
In my excel file I have a field called Price which I add a number to like 2.99 3.99 and so forth.
if i type the stuff out manually in this format
id authorfirst authorlast title price keywords
1 tony smith a book 1.99 blah,blah
it works fine
but if i paste from access into excel the price files get the little thing convert text to number.
if i leave it alone it throws exception saying it can't cast double. so i changed it to getdouble
same error. i converted it to number. tried again same exception. if i take and click on the field and edit it manually to say 3.99 then bam works fine. Just curious if you ever ran into this issue and if so how do you resolve it ?
|
|
|
|
|
Nope, not really but I see what you mean.
Could be many reasons:
1) Check to see if your excel data doesn't contain any "'" sign at the beging
2) Try no formatting => leave the cells to general.
3) If all this fails then two options:
a) check your regional and language settings. See what's the decimal separator.
While C# by default uses the Culture Invariant/Neutral, excel uses the system
settings. Ex: in US Language and settings 300.05 => OK it loads it as a number
in Romanian 300,05 => to load it as a number.
b) if all this fails and hell gets lose than go to the last resource and fight back with
some VBA => macros.
Create a macro that transforms your cells.
|
|
|
|
|
i got it to work. simply took and typed in a number in another field. selected it and copied.
then selected all the price values i wanted to use. right clicked paste special and selected formulas and number formating and it worked just fine. thanks again.
Now If i can only figure out this dang treenode thing I'll be cookin with gas.
|
|
|
|