|
Try
string MyPath = f+"\\CDINDEX.txt";
Put a break after this and look at the value of MyPath. I would hope there would be some obvious error, but if not then copy the value and put it in the command prompt and make sure it works.
topcoderjax
|
|
|
|
|
What is f?
Could you quickly try
<br />
using (StreamReader sr = new StreamReader("C:\\test\\CDINDEX.txt"))<br />
instead?
Arti
|
|
|
|
|
Like Bekjong said, the correct way to put a path together would be to use the Path class and it's Combine method:
string filepath = Path.Combine(f, @"CDINDEX.txt");
using (StreamReader sr = new StreamReader(filepath)
|
|
|
|
|
I have added a group of controls to a form using code and added the controls to the form collection.
How can I later iterate through all of the controls on the form and drop the (Textbox) controls that I added earlier?
I can use a property in the control to do the ID, but I need code to iterate through all controls, and to drop selected controls.
A code sample would be great!
Joseph Stanish
|
|
|
|
|
The easiest way to remove a control is to keep the reference from when you created it, and use use the Remove method:
SomeParent.Controls.Remove(SomeTextbox);
---
single minded; short sighted; long gone;
|
|
|
|
|
(I guess I could dim a collection of textboxes and add each of my textbox controls to this collection, and then when it is time to remove these controls go throught this collection and drop the controls form the form ...
Is the correct?
That sounds like a very good idea! Could you please provide a brief code sample?
Joseph Stanish
|
|
|
|
|
What's so hard about iterating through your controls? If you can add the pro grammatically it's just as easy to remove them, isn't it?
this.SuspendLayout();
Collection<Control> temp = new Collection<Control>();
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(TextBox) && c.Tag == "drop me")
{
temp.Add(c);
}
}
foreach (Control c in temp)
{
this.Controls.Remove(c);
c.Dispose();
}
temp = null;
this.ResumeLayout();
Standards are great! Everybody should have one!
|
|
|
|
|
Perfect. Thanks.
Joseph Stanish
|
|
|
|
|
Hello,
Very nice idea to copy the instances in a seperate Collection instead of Cloning the Collection!
Never thought of this bevor!
Thanks for that!
All the best,
Martin
|
|
|
|
|
Bekjong wrote: if (c.GetType() == typeof(TextBox)
or better yet
if (c is TextBox && ... )
|
|
|
|
|
Umm. Iterate through the Controls collection of the Form and set the Parent to null for the control you want removed from the form.
Marc
Thyme In The CountryInteracxPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
I need a code sample
Joseph Stanish
|
|
|
|
|
Maybe a "please" would help!
|
|
|
|
|
here you are ... "Please"
by the way, you do not need to reply; instead of searching the form, I am going to keep a list of added controls, I will then iterate through my own list to drop the correct controls.
Thanks.
Joseph Stanish
|
|
|
|
|
Hello,
Joseph Stanish wrote: here you are ... "Please"
by the way, you do not need to reply
No need to be ironic and/or rude!
Joseph Stanish wrote: instead of searching the form, I am going to keep a list of added controls, I will then iterate through my own list to drop the correct controls.
Thats a very good Idea!
I would use an ArrayList to hold the instances of the TextBoxes.
I would also be carefull, when iterating over an Collection and Removing an item out of this Collection.
For that, I would Clone the ArrayList and iterate over the Clone, cast each object to TextBox (with "as"), do my validation, and remove it from the original Collection!
All the best,
Martin
|
|
|
|
|
Joseph Stanish wrote: I need a code sample
Seriously, if you can't write:
foreach(Control ctrl in form.Controls)
{
if (ctrl.Tag==myTag)
{
ctrl.Parent=null;
break;
}
}
Then I have to ask, what are you doing pretending to be a programmer?
Marc
Thyme In The CountryInteracxPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
Hi,
I am writing the user control,inside user control i am adding button
control. I have collection of buttons,button is geting added using property editor. I want user should not be able to move the button at design time (when user drops my user control on the Form)
I tried with Locked property of button but we can not set this property at run time.
How should i avoid the user to move the button??
Thanks,
Tushar
|
|
|
|
|
Hi,
I provide my user controls in a separate "Lib" file, and controls over my user controls cannot be moved by the developer at the design time. How are u able to move the buttons on user controls?
Manoj
Never Give up
|
|
|
|
|
Hi,
I am adding buttons like this,the event is fired from onInsert of the CollectionBase derived class ButtonList
void _ButtonList_OnCustomButtonAdded(CustomButton newCustomButton)
{
int customButtonWidth = 0;
foreach (CustomButton customButton in _tabPagesList)
{
customButtonWidth = customButtonWidth +
customButton.Width;
}
newCustomButton.Left = customButtonWidth - newCustomButton.Width;
newCustomButton.LeftPos = customButtonWidth - newCustomButton.Width;
newCustomButton.Top = 0;
Graphics g = this.CreateGraphics();
float width = g.MeasureString(newCustomButton.Text, BoldTabFont).Width;
newCustomButton.Width = (int)width;
newCustomButton.Parent = this;
newCustomButton.Show();
newCustomButton.Click += new EventHandler(newCustomButton_Click);
newCustomButton.OnCustomButtonMouseDown += new CustomButton.CustomButtonMouseDown(newCustomButton_OnCustomButtonMouseDown);
this.Controls.Add(newCustomButton);
newCustomButton.BringToFront();
}
buttons added are movable at design time
Thanks,
Tushar
|
|
|
|
|
Hello,
How is newCustomButton instanciated?
Tried it in a Test Program, but I never made it like you discriped?
All the best,
Martin
|
|
|
|
|
Hi Martin,
I am having the list like shown below,list of custom buttons,user can add the buttons to my user control from property editor, i have exposed public property from user control.
public TabsPagesList TabPagesList
{
get
{
return _tabPagesList;
}
set
{
if (value != null)
{
_tabPagesList.Add(value);
}
}
}
[DesignTimeVisible(true)]
public class TabsPagesList : CollectionBase
{
public delegate void CustomButtonAdded(CustomButton newTextBox);
public delegate void CustomButtonRemoved(CustomButton newCustomButton);
public event CustomButtonAdded OnCustomButtonAdded;
public event CustomButtonRemoved OnCustomButtonRemoved;
public TabsPagesList()
{
}
public CustomButton this[int index]
{
get
{
return (CustomButton)List[index];
}
set
{
List[index] = (CustomButton)value;
}
}
public void AddCustomButton(CustomButton lb)
{
List.Add((CustomButton)lb);
//base.InnerList.Add(lb);
}
public void Add(TabsPagesList list)
{
base.InnerList.AddRange(list);
}
public bool Contains(CustomButton customButton)
{
return List.Contains(customButton);
}
protected override void OnInsert(int index, object value)
{
base.OnInsert(index, value);
}
protected override void OnInsertComplete(int index, object value)
{
base.OnInsertComplete(index, value);
if (OnCustomButtonAdded != null)
OnCustomButtonAdded((CustomButton)value);
}
protected override void OnRemove(int index, object value)
{
MessageBox.Show("OnRemoveComplete");
if (OnCustomButtonRemoved != null)
{
MessageBox.Show("calling OnCustomButtonRemoved");
OnCustomButtonRemoved((CustomButton)value);
}
base.OnRemove(index, value);
}
protected override void OnRemoveComplete(int index, object value)
{
base.OnRemoveComplete(index, value);
MessageBox.Show("OnRemoveComplete");
if (OnCustomButtonRemoved != null)
{
MessageBox.Show("calling OnCustomButtonRemoved");
OnCustomButtonRemoved((CustomButton)value);
}
}
}
public class CustomButton : Button
{
private ArrayList childControls;
private bool isSelected;
private int _leftPos;
public delegate void CustomButtonMouseDown(MouseEventArgs e);
public event CustomButtonMouseDown OnCustomButtonMouseDown;
public CustomButton()
{
childControls = new ArrayList();
//Load three images here
}
public int LeftPos
{
get
{
return _leftPos;
}
set
{
_leftPos = value;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
MessageBox.Show("Inside Button class MouseDown");
base.OnMouseDown(e);
if (OnCustomButtonMouseDown != null)
OnCustomButtonMouseDown(e);
}
public bool IsSelected
{
get
{
return isSelected;
}
set
{
isSelected = value;
}
}
public void AddControl(Control cntrl)
{
childControls.Add(cntrl);
}
public ArrayList InnerControls
{
get
{
return childControls;
}
}
}
Thanks,
Tushar
|
|
|
|
|
Hello,
Make the button a private member of your UserControl!
All the best,
Martin
|
|
|
|
|
UNDER WORDPAIR.CS
using System;
using System.Collections.Generic;
using System.Text;
namespace Assignment_No._2
{
class WordPair
{
string[] rightpair = new string[5]
{"below\tunter","blue\tgelb","cat\tdie katze","red\trot","the dog\tder Hund","to read\tlesen"
};
public string CheckMatch(string english, string german)
{
string combined = english + "\t" + german;
if (Array.IndexOf(rightpair, combined) != -1)
{
return String.Format("'{0}'was correctly matched with '{1}'", english,
german);
}
else
{
return String.Format("No match was found for '{0}'with '{1}'",
english, german);
}
}
}
}
________________________________________________________________________
UNDER FORM 1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Assignment_No._
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WordPair wp = new WordPair();
string result1 = wp.CheckMatch("below","unter");
string result2 = Environment.NewLine + wp.CheckMatch("blue", "rot");
richTextBox1.Text = result1 + result2;
}
}
}
___________________________________________________________________________
UNDER PROGRAM C.S
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Assignment_No._
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//WordPair wp = new WordPair();
//string result1 = wp.CheckMatch("below", "unter");
//string result2 = Environment.NewLine + wp.CheckMatch("blue", "rot");
//richTextBox1.Text = result1 + result2;
}
}
}
___________________________________________________________________________
BUILD ERRORS
Error 2 The type or namespace name 'WordPair' could not be found (are you missing a using directive or an assembly reference?) E:\Documents and Settings\Ntiko\My Documents\Visual Studio 2005\Projects\Assignment No.2\Assignment No.2\Form1.cs 20 13 Assignment No.2
------------------------------------------
Error 3 The type or namespace name 'WordPair' could not be found (are you missing a using directive or an assembly reference?) E:\Documents and Settings\Ntiko\My Documents\Visual Studio 2005\Projects\Assignment No.2\Assignment No.2\Form1.cs 20 31 Assignment No.2
---------------------------------------------
Error 4 The type or namespace name 'WordPair' could not be found (are you missing a using directive or an assembly reference?) E:\Documents and Settings\Ntiko\My Documents\Visual Studio 2005\Projects\Assignment No.2\Assignment No.2\Program.cs 18 15 Assignment No.2
----------------------------------------
Error 5 The type or namespace name 'WordPair' could not be found (are you missing a using directive or an assembly reference?) E:\Documents and Settings\Ntiko\My Documents\Visual Studio 2005\Projects\Assignment No.2\Assignment No.2\Program.cs 18 33 Assignment No.2
-------------------------------------------------
Error 6 The name 'richTextBox1' does not exist in the current context E:\Documents and Settings\Ntiko\My Documents\Visual Studio 2005\Projects\Assignment No.2\Assignment No.2\Program.cs 21 15 Assignment No.2
--------------------------------------------------
Error 7 Invalid rank specifier: expected ',' or ']' E:\Documents and Settings\Ntiko\My Documents\Visual Studio 2005\Projects\Assignment No.2\Assignment No.2\WordPair.cs 10 5 Assignment No.2
-----------------------------------------------------
Also pop up message saying that;
Visual studio cannot start debugging because the debug target E:\Documents and Settings\Ntiko\my Documents\visual studio 2005\projetcs\Assignment No.2\Assignment No.2\bin\Debug\Assignment No.2.exe' is missing. Please build the project and retry or set the outpath and Assembly Name properties appropriately to point at the correct location for the target assembly.
Any suggestions resolving this kind of staff?????
Ntoki
|
|
|
|
|
As the class and the code that uses it are in separate namespaces, you either need a using statement to locate the namespace of the class, or you have to specify the complete namespace everytime you use the name of the class.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi,
I need to send startDate to a Service like following format.But I need to send it as a DateTime Object NOT like string format.So How do I send following Date with DateTime Object?
<startdate>2007-07-29T00:00:00.0000000+05:30
Please kindly reply me.
Thanks in advance.
|
|
|
|