|
Sorry about confusing anybody. Here is what I want
My Playlist is displayed in ListBox named list
with contents
1. SongABc
2. Song Dev
3. Vid34
4. Clip5
5. ABC and so on
I need to delete an item from that
for that I'm doing
this.list.Items.RemoveAt(index);
Now I need to update the IndexNumber of each entry in the Playlist so that after deleting "Vid34"
My list shows
1. SongABc
2. Song Dev
3. Clip5
4. ABC and so on
I can READ ALL items of list as
IEnumerator enm = this.list.Items.GetEnumerator();
int i = 0;
for(i = 0; i < index; i ++ )
enm.MoveNext();
//Now I'm at the place where I Delete the Entry
//all the Following Items need to update their Numerical Index Decremented by one
for(i = index; i < list.Items.Count; i ++)
{
String entry = enm.Current.ToString();
String newVal = getNewVal(entry); // Strip Index Value so that "4. Clip5 becomes just Clip5"
//Here I need to set the Current Entry with new Val something like
this.list.itemAt(i) = newVal; // But no such method exists
neither can I do
enm.Current = newVal; // Because it is a readonly property
}
I can clear my playlist and readd everything but that would be waste of resources
|
|
|
|
|
Aah. I see what you're getting at. Well, the simple way to do it would be to use list.Items[i] = newVal; in the loop. You can simplify the logic quite a lot:
for (int i = 0; i < list.Items.Count; i++)
{
string entry = enm.Current.ToString();
list.Items[i] = getNewVal(entry);
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Thanks Man. You Saved Me...
After reading your last post I'm looking like an idiot.
well I'm new to C#
Thanks...
|
|
|
|
|
Sukhjinder_K wrote: After reading your last post I'm looking like an idiot.
Nope, not at all. Don't put yourself down - at least you had a go before posting. There are too many who would just have asked without trying anything themself.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Yup this is how we All Evolve by Being a Community...
All the Best..
|
|
|
|
|
Use the Items collection of your ListBox to modify the contents of the list.
Paul
|
|
|
|
|
Hi,
there is a different and better way to achieve a numbered list: ListBox (and ComboBox) support
"OwnerDraw" mode, which means you paint the items yourself in any way you like, instead
of their string value being shown as is. So what you could do is add a DrawItem handler
that does a Graphics.DrawString(itemIndex.ToString()+". "+item.ToString());
Doing this will automatically show the text with its number, whatever happens to the list.
You would have to get the itemIndex from DrawItemEventArgs.Index, and item from
myListBox.Items[itemIndex].
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
am trying to develop one aplication to read a particular node in an xml file. but somewhere i goes wrong and not working.......
plz help me to find out the error.....
In the following xml file i want to find out the last name.
This is the xml
<?xml version="1.0" encoding="UTF-8" ?>
<family>
<name gender="male">
<firstname>Tom</firstname>
<lastname>Smith</lastname>
</name>
</family>
and the code is --------
FileStream fs = new FileStream("D:\\Myfolder\\gender.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
xmldoc.Load(fs);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("name");
for (int a = 0; a < xmlnode.Count; a++)
{
if (xmlnode[a].Attributes[0].Value == "gender")
// match your attributes
{ //codes
lblcnt.Text=a.ToString();
String firstNameValue = reader.ReadElementString("gender");
Lblmsg.Text=" FirstName: "+firstNameValue;
}
I tried this one also=======
XmlTextReader reader = new XmlTextReader ("D:\\Myfolder\\gender.xml");
XmlDocument xmldoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader ("C:\\gender.xml");
try
{
while (!reader.EOF)
{
reader.Read();
if(reader.IsStartElement() )
{
reader.Read();
xmldoc.SelectSingleNode("family/name/firstname");
XmlNode xmlnode1=xmldoc.GetElementsByTagName("firstname");
String firstNameValue = reader.ReadElementString("firstname");
xmldoc.SelectSingleNode("lastname");
String lastNameValue = reader.ReadElementString("lastname");
Lblmsg.Text=" FirstName: "+firstNameValue + " LastName: " + lastNameValue;
}
}
reader.Close();
}
catch (Exception err )
{
Lblmsg.Text="Error: " + err.ToString();
}
-- modified at 23:25 Wednesday 12th September, 2007
|
|
|
|
|
This is a disaster
princymg wrote: xmldoc.SelectSingleNode("family/name/firstname");
This would work if
a - you loaded your xml into xmldoc, and
b - you grabbed the return value from the call
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I think this will help U
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("gender.xml"));
DataTable dt = ds.Tables["family"];
DataRow dr;
for (int i = 0; dt.Rows.Count > i; i++)
{
dr = dt.Rows[i];
String firstNameValue = dr["firstname"].ToString();
String lastNameValue =dr["lastname"].ToString();
Lblmsg.Text=" FirstName: "+firstNameValue + " LastName: " + lastNameValue;
}
Jintal Patel
|
|
|
|
|
i think XQuery will help u out
XQuery is to XML what SQL is to database tables.
http://www.w3schools.com/xquery/xquery_intro.asp
|
|
|
|
|
I got the code......
string str;
XmlTextReader reader = new XmlTextReader ("D:\\Foldername\\tx1.xml");
try
{
while (reader.Read())
{
if(reader.IsStartElement() )
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "jid")
{
str=reader.ReadString();
//Lblmsg.Text="Article Title is : "+ reader.Name+ " : "+reader.ReadString();
Lblmsg.Text="Article Title is : "+ reader.Name+ " : "+str;
lblcnt.Text=str;
}
}
}
reader.Close();
}
catch (Exception err )
{
Lblmsg.Text="Error: " + err.ToString();
}
Thanks for the help....................
|
|
|
|
|
Dudez,
Is there a way to save the username and password when user login.
Example:
I will access computer name \\ROBO then username and password form pop up.Think on computer neighborhood. When that user input his/her username and password. It will save on temporary file. Is it possible? How to do that? Much better if you can give a link or an existing application that can be downloaded (3rd party).
Thanks in advance,
jeof
******************************
I just want to
know everything
|
|
|
|
|
You can store any info you like, whereever you like. Storing passwords is obviously sensitive, however.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi I'm posting a new question in case Malcolm doesn't read my reply in time.
Basically what is wrong with this code? I want to automatically check the checklistbox items depending on if the items match the employees TechnicalSkillsID in the database table. Malcolm gave me a web form example which was a great response except I forgot to tell him I was using a winform.
can you help at all?
int i;<br />
<br />
for (i = 0; i <= (techSkillsCheckListBox2.Items.Count - 1); i++)<br />
{<br />
while (adoDR.Read())<br />
{<br />
sql = "Select em.TechnicalSkillsID,t.ProgLanguagesDatabase from EmpSkills em,TechnicalSkills t where EmployeeID = '" + FirstnameText.Text + "' and em.TechnicalSkillsID = t.TechnicalSkillsID";<br />
<br />
DataRow[] rows = dataSet1.TechnicalSkills.Select();<br />
foreach (DataRow row in rows)<br />
{<br />
string techID = row["TechnicalSkillsID"].ToString();<br />
techSkillsCheckListBox2.SetItemChecked(i, true);<br />
}<br />
}<br />
}
Sianny aka Sharny
|
|
|
|
|
falles01 wrote: for (i = 0; i <= (techSkillsCheckListBox2.Items.Count - 1); i++)
Why not
i < techSkillsCheckListBox2.Items.Count ?
Or even
foreach (CheckBox box in techSkillsCheckListBox2.Items) ?
This code is really broken. What you want to do, is fill a list with the items that are selected, then go through each check box and do something like
checkbox.Checked = (myListOfItems.Contains(theKEyForThisCheckbox));
Of course, I just invented some variables, assume the Tag of the checkbox contains the key value, so you can look it up. The code you're presenting does a nested loop, and just sets each box to be checked, over and over again.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks but the part you are talking about that is wrong, is actually the part that is correct and gives the correct value. I got that off msdn. Yes I want to fill a list with items but as i said, I can't use listitems as I'm using a winform so I would like to know how I do that exactly. How do you check the items against the ID's against an empID in the database?
Sianny aka Sharny
|
|
|
|
|
If you have a list of items and want to fill the control with them, you should be able to set the control's DataSource property with the list, and it should work.
That code is from MSDN ? It's REALLY messy, especially with the nested loop. Do you have a link ? I believe you, I'm just interested.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm not sure what you mean but i think I have filled the list already as you said as the items are there. I just need the ticked items to save as correct ID's in the database against a given employee. I would've used bits and pieces of msdn stuff so that might be why its messy. I didn't copy a whole paragraph of code, just a line here and there.
<br />
public override void TechnicalSkillsList()<br />
{<br />
<br />
DataSet1TableAdapters.TechnicalSkillsTableAdapter technicalskillsTableAdapter = new ResourceSearchTool.DataSet1TableAdapters.TechnicalSkillsTableAdapter();<br />
<br />
DataSet1.TechnicalSkillsDataTable techSkillsDT = technicalskillsTableAdapter.GetData();<br />
<br />
foreach (DataSet1.TechnicalSkillsRow techSkillsRow in techSkillsDT.Rows)<br />
this.techSkillsCheckListBox2.Items.Add(techSkillsRow.ProgLanguagesDatabase);<br />
<br />
}
|
|
|
|
|
and how do you fill a list with the checked items by the way?
|
|
|
|
|
and what sort of list? I have a checkedlist box which is filled with data from the dataset.
|
|
|
|
|
Hey,
I am trying to draw a line on a bitmap. I have tried using System.Drawing.Graphics, however this apparently only works with forms. When I try the following code:
System.Drawing.Graphics.DrawLine(drawerpen, lastpoint, currentpoint);
I get an error saying that I must create an object instance to use this. However, System.Drawing.Graphics has no constructors, so I cannot create an instance such as:
System.Drawing.Graphics lineDrawer = new System.Drawing.Graphics();
How can I draw lines on a bitmap?
|
|
|
|
|
Klazen wrote: however this apparently only works with forms.
What makes you say that ?
Klazen wrote: I get an error saying that I must create an object instance to use this
Yes.
Klazen wrote: How can I draw lines on a bitmap?
Graphics graphics = Graphics.FromBitmap(myBitmap);
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank you very much
I say that because the only working instance of Graphics I found was through a form, such as using it to draw lines on a form.
|
|
|
|
|
Ah, sure, because in the paint event, it's been created for you.
A lot of .NET classes use static factory methods instead of constructors, that's always something that's good to look for, in that scenario.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|