Click here to Skip to main content
15,885,216 members
Home / Discussions / C#
   

C#

 
Questionmultiple reports in a single reportviwer Pin
Enobong Adahada14-Oct-09 4:04
Enobong Adahada14-Oct-09 4:04 
AnswerRe: multiple reports in a single reportviwer Pin
EliottA14-Oct-09 4:54
EliottA14-Oct-09 4:54 
GeneralMobile phone programs Pin
Enobong Adahada14-Oct-09 3:59
Enobong Adahada14-Oct-09 3:59 
GeneralRe: Mobile phone programs Pin
Not Active14-Oct-09 4:15
mentorNot Active14-Oct-09 4:15 
GeneralRe: Mobile phone programs Pin
dan!sh 14-Oct-09 4:17
professional dan!sh 14-Oct-09 4:17 
GeneralRe: Mobile phone programs Pin
EliottA14-Oct-09 4:56
EliottA14-Oct-09 4:56 
AnswerRe: Mobile phone programs Pin
solomonope14-Oct-09 7:08
solomonope14-Oct-09 7:08 
QuestionUserControl and Collections in Designer Pin
cinias14-Oct-09 3:10
cinias14-Oct-09 3:10 
Hello,

I've wrote UserControl where one of properties is collection. Item of collection is object of type GroupClass. Code below:

[Serializable]
public class GroupClass
{
private string pGrpupName;
private Control pGroupControl;

[Category("Group")]
[Description("Definition")]
public string GroupName
{
get { return pGrpupName; }
set { pGrpupName = value; }
}

[Category("Group")]
[Description("Definition")]
[Browsable(false)]
public Control GroupControl
{
get { return pGroupControl; }
set { pGroupControl = value; }
}
}
And after when I add item to collection also groupbox should show on UC. I've override some methods in my Collection. It works. But it doesn't when I try to remove item in designer. Groupbox is still there and method RemoveItem doesn't works Frown | :(

public class WRListClass<T> : Collection<T>
{
public event EventHandler<ItemInsertedArgs<T>> BeforeItemInserted;
public event EventHandler<ItemRemovedArgs<T>> BeforeItemRemoved;
public event EventHandler<ItemSetArgs<T>> BeforeItemSet;
public event EventHandler<ItemInsertedArgs<T>> AfterItemInserted;
public event EventHandler<ItemRemovedArgs<T>> AfterItemRemoved;
public event EventHandler<ItemSetArgs<T>> AfterItemSet;
public event EventHandler ListChanged;


protected override void InsertItem(int index, T item)
{
EventHandler<ItemInsertedArgs<T>> beforehandler = BeforeItemInserted;
EventHandler<ItemInsertedArgs<T>> afterhandler = AfterItemInserted;
EventHandler handlerListChanged = ListChanged;
if (beforehandler != null)
{
beforehandler(this, new ItemInsertedArgs<T>(index, item));
}
base.InsertItem(index, item);
if (afterhandler != null)
{
afterhandler(this, new ItemInsertedArgs<T>(index, item));
}
if (handlerListChanged != null)
{
handlerListChanged(this, null);
}
}

public new bool Remove(T item)
{
return base.Remove(item);
}

public new void RemoveAt(int index)
{
base.RemoveAt(index);
}

protected override void RemoveItem(int index)
{
EventHandler<ItemRemovedArgs<T>> beforehandler = BeforeItemRemoved;
EventHandler<ItemRemovedArgs<T>> afterhandler = AfterItemRemoved;
EventHandler handlerListChanged = ListChanged;
T item = default(T);
if (index >= 0)
item = this[index];
WRListClass<T> old = this;
if (beforehandler != null)
{
beforehandler(this, new ItemRemovedArgs<T>(index, item));
}
base.RemoveItem(index);
if (afterhandler != null)
{
afterhandler(this, new ItemRemovedArgs<T>(index, item));
}
if (handlerListChanged != null)
{
if (old != this)
handlerListChanged(this, null);
}
}


protected override void SetItem(int index, T item)
{
EventHandler<ItemSetArgs<T>> beforehandler = BeforeItemSet;
EventHandler<ItemSetArgs<T>> afterhandler = AfterItemSet;
EventHandler handlerListChanged = ListChanged;
WRListClass<T> old = this;
if (beforehandler != null)
{
beforehandler(this, new ItemSetArgs<T>(index, item));
}
base.SetItem(index, item);
if (afterhandler != null)
{
afterhandler(this, new ItemSetArgs<T>(index, item));
}
if (handlerListChanged != null)
{

if (old != this)
handlerListChanged(this, null);
}
}
}

public class ItemInsertedArgs<T> : EventArgs
{
public int Index;
public T Item;

public ItemInsertedArgs(int index, T item)
{
this.Index = index;
this.Item = item;
}
}


public class ItemSetArgs<T> : EventArgs
{
public int Index;
public T Item;

public ItemSetArgs(int index, T item)
{
this.Index = index;
this.Item = item;
}
}

public class ItemRemovedArgs<T> : EventArgs
{
public int Index;
public T Item;

public ItemRemovedArgs(int index, T item)
{
this.Index = index;
this.Item = item;
}
}


----USERCONTROL



[Designer("System.Windows.Forms.Design.ParentControlDesigner", "IDesigner")]
public partial class UserControl1 : UserControl
{
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
private WRListClass<GroupClass> pGroups = new WRListClass<GroupClass>();
public UserControl1()
{
InitializeComponent();

pGroups.AfterItemInserted += new EventHandler<ItemInsertedArgs<GroupClass>>(pGroups_AfterItemInserted);
pGroups.BeforeItemRemoved += new EventHandler<ItemRemovedArgs<GroupClass>>(pGroups_BeforeItemRemoved);

}

void pGroups_BeforeItemRemoved(object sender, ItemRemovedArgs<GroupClass> e)
{
if (e != null)
{
if (e.Item != null)
{
if (e.Item.GroupName != null)
{
if (e.Item.GroupName.Trim() != "")
{
if (e.Item.GroupControl != null)
{
e.Item.GroupControl.Parent = null;
this.Controls.Remove(e.Item.GroupControl);
e.Item.GroupControl.Dispose();
}
}
}
}
}
}

void pGroups_AfterItemInserted(object sender, ItemInsertedArgs<GroupClass> e)
{
if (e != null)
{
if (e.Item != null)
{
if (e.Item.GroupName != null)
{
if (e.Item.GroupName.Trim() != "")
{
if (e.Item.GroupControl == null)
{
e.Item.GroupControl = new GroupBox();
e.Item.GroupControl.TabIndex = pGroups.Count + 1;
e.Item.GroupControl.Text = e.Item.GroupName;
e.Item.GroupControl.Name = e.Item.ToString();
e.Item.GroupControl.Parent = this;
this.Controls.Add(e.Item.GroupControl);
e.Item.GroupControl.Dock = DockStyle.Top;
e.Item.GroupControl.BringToFront();
}
}
}
}
}
}


[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
[EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public WRListClass<GroupClass> Groups
{
get { return pGroups; }
set {
pGroups = value;
}
}

}


Please help! Thanks!
AnswerRe: UserControl and Collections in Designer Pin
Henry Minute14-Oct-09 3:41
Henry Minute14-Oct-09 3:41 
Questionbiometric sdk for hp ipaq pda Pin
solomonope14-Oct-09 2:30
solomonope14-Oct-09 2:30 
AnswerRe: biometric sdk for hp ipaq pda Pin
Richard MacCutchan14-Oct-09 3:07
mveRichard MacCutchan14-Oct-09 3:07 
QuestionGetting corrupt data from NetworkStream.Read Pin
JFord123414-Oct-09 1:34
JFord123414-Oct-09 1:34 
AnswerRe: Getting corrupt data from NetworkStream.Read Pin
Richard MacCutchan14-Oct-09 3:20
mveRichard MacCutchan14-Oct-09 3:20 
GeneralRe: Getting corrupt data from NetworkStream.Read Pin
JFord123414-Oct-09 5:51
JFord123414-Oct-09 5:51 
QuestionWebservice and proxy Pin
Mogyi13-Oct-09 23:11
Mogyi13-Oct-09 23:11 
AnswerRe: Webservice and proxy Pin
Keith Barrow14-Oct-09 2:00
professionalKeith Barrow14-Oct-09 2:00 
GeneralRe: Webservice and proxy Pin
Mogyi14-Oct-09 2:15
Mogyi14-Oct-09 2:15 
AnswerRe: Webservice and proxy Pin
Hristo-Bojilov14-Oct-09 2:04
Hristo-Bojilov14-Oct-09 2:04 
GeneralRe: Webservice and proxy Pin
Mogyi14-Oct-09 2:17
Mogyi14-Oct-09 2:17 
QuestionOpening a named browser window from a windows application Pin
mSh198513-Oct-09 22:26
mSh198513-Oct-09 22:26 
QuestionAdding Data to datagridview [modified] Pin
ldsdbomber13-Oct-09 20:36
ldsdbomber13-Oct-09 20:36 
AnswerRe: Adding Data to datagridview Pin
OriginalGriff13-Oct-09 23:50
mveOriginalGriff13-Oct-09 23:50 
GeneralRe: Adding Data to datagridview Pin
ldsdbomber14-Oct-09 1:22
ldsdbomber14-Oct-09 1:22 
Questionwrite to a excel sheet that is already open Pin
ananya choudhury13-Oct-09 17:18
ananya choudhury13-Oct-09 17:18 
QuestionApp Communication via screen reads Pin
Rizean13-Oct-09 15:54
Rizean13-Oct-09 15:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.