Click here to Skip to main content
15,897,181 members
Home / Discussions / C#
   

C#

 
GeneralRe: Is there a setting in visual studio for the Convert.ToDateTime? Pin
Support1239-Nov-06 2:32
Support1239-Nov-06 2:32 
GeneralRe: Is there a setting in visual studio for the Convert.ToDateTime? Pin
Pete O'Hanlon9-Nov-06 4:14
mvePete O'Hanlon9-Nov-06 4:14 
GeneralRe: Is there a setting in visual studio for the Convert.ToDateTime? Pin
Support1239-Nov-06 5:27
Support1239-Nov-06 5:27 
GeneralRe: Is there a setting in visual studio for the Convert.ToDateTime? Pin
Pete O'Hanlon9-Nov-06 9:11
mvePete O'Hanlon9-Nov-06 9:11 
QuestionTo make possible to manage position and size of controls by mouse Pin
wasek20018-Nov-06 23:59
wasek20018-Nov-06 23:59 
AnswerRe: To make possible to manage position and size of controls by mouse Pin
mark_w_9-Nov-06 0:27
mark_w_9-Nov-06 0:27 
QuestionRe: To make possible to manage position and size of controls by mouse Pin
wasek20019-Nov-06 4:31
wasek20019-Nov-06 4:31 
QuestionAbstract collection in property grid Pin
mark_w_8-Nov-06 23:56
mark_w_8-Nov-06 23:56 
Hi,

The background:

I have a class "Search" that has a collection in it. This collection is of type "criteria", where "criteria" is an abstract class. The reason being is that i have some concrete classes "IntCriteria", "StringCriteria", "BoolCritera" that i want stored in the collection and they all inherit from "criteria".

To the problem:

I bind "Search" to a property grid, it works fine and i can see/edit all the properties of search, but when i try i add an item to the collection of "criteria" i cant because it does not know what concrete classes to give me as the option to add (see here http://img242.imageshack.us/img242/5803/exampleko9.jpg to see what i want, this is to add columns to a data grid view). Is there a way i can tag "IntCriteria", "StringCriteria" and "BoolCritera" so that the property grid sees them as a type of "criteria".

if not then, is there anyway i can list "IntCriteria", "StringCriteria" or"BoolCritera" in the add new item screen.

Hope that made sense!!!


To Recreate the problem, make a windows application, create this file (i have put multiple classes in one file for ease)(its only example code, not my actual code!)

<br />
using System;<br />
<br />
using System.Collections.Generic;<br />
<br />
using System.Text;<br />
<br />
using System.Collections;<br />
<br />
namespace TestApp<br />
<br />
{<br />
<br />
public class Search<br />
<br />
{<br />
<br />
private string _A;<br />
<br />
private string _B;<br />
<br />
private CriteriaCollection _cc = new CriteriaCollection();<br />
<br />
public string A<br />
<br />
{<br />
<br />
get { return _A; }<br />
<br />
set { _A = value; }<br />
<br />
}<br />
<br />
public string B<br />
<br />
{<br />
<br />
get { return _B; }<br />
<br />
set { _B = value; }<br />
<br />
}<br />
<br />
public CriteriaCollection cc<br />
<br />
{<br />
<br />
get { return _cc; }<br />
<br />
set { _cc = value; }<br />
<br />
}<br />
<br />
public Search()<br />
<br />
{<br />
<br />
}<br />
<br />
}<br />
<br />
public class CriteriaCollection : CollectionBase<br />
<br />
{<br />
<br />
public CriteriaCollection()<br />
<br />
{<br />
<br />
}<br />
<br />
public void Add(Criteria C)<br />
<br />
{<br />
<br />
this.InnerList.Add(C);<br />
<br />
}<br />
<br />
public void Remove(Criteria element)<br />
<br />
{<br />
<br />
InnerList.Remove(element);<br />
<br />
}<br />
<br />
public Criteria this[int index]<br />
<br />
{<br />
<br />
get { return (Criteria)InnerList[index]; }<br />
<br />
}<br />
<br />
public void CopyTo(Criteria[] target, int index)<br />
<br />
{<br />
<br />
InnerList.CopyTo(target, index);<br />
<br />
}<br />
<br />
public int IndexOf(Criteria element)<br />
<br />
{<br />
<br />
return InnerList.IndexOf(element);<br />
<br />
}<br />
<br />
public bool Contains(Criteria element)<br />
<br />
{<br />
<br />
return InnerList.Contains(element);<br />
<br />
}<br />
<br />
public void Insert(int index, Criteria element)<br />
<br />
{<br />
<br />
InnerList.Insert(index, element);<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
//abstract base class, with all the common factors to any criteria<br />
<br />
public abstract class Criteria<br />
<br />
{<br />
<br />
private string _C;<br />
<br />
private string _D;<br />
<br />
<br />
public string C<br />
<br />
{<br />
<br />
get<br />
<br />
{<br />
<br />
return _C;<br />
<br />
}<br />
<br />
set<br />
<br />
{<br />
<br />
_C = value;<br />
<br />
}<br />
<br />
}<br />
<br />
public string D<br />
<br />
{<br />
<br />
get<br />
<br />
{<br />
<br />
return _D;<br />
<br />
}<br />
<br />
set<br />
<br />
{<br />
<br />
_D = value;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
//Class to deal with any ints<br />
<br />
public class IntCriteria : Criteria<br />
<br />
{<br />
<br />
public IntCriteria()<br />
<br />
{<br />
<br />
<br />
}<br />
<br />
public int DoSomeIntStuff()<br />
<br />
{<br />
<br />
return 0;<br />
<br />
}<br />
<br />
}<br />
<br />
 <br />
<br />
//Class to deal with any strings<br />
<br />
public class StringCriteria : Criteria<br />
<br />
{<br />
<br />
public StringCriteria()<br />
<br />
{<br />
<br />
}<br />
<br />
public string DoSomeStringStuff()<br />
<br />
{<br />
<br />
return "Stuff done";<br />
<br />
}<br />
<br />
}<br />
<br />
//Class to deal with any Bools<br />
<br />
public class BoolCriteria : Criteria<br />
<br />
{<br />
<br />
<br />
public BoolCriteria()<br />
<br />
{<br />
<br />
}<br />
<br />
public bool DoSomeBooleanStuff()<br />
<br />
{<br />
<br />
return true;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />






Then on a form add a property grid and add

<br />
private void Form1_Load(object sender, EventArgs e)<br />
<br />
{<br />
<br />
Search s = new Search();<br />
<br />
this.propertyGrid1.SelectedObject = s;<br />
<br />
}<br />
<br />




Run the form and try and add and item to cc in the property grid


TIA

Mark
AnswerRe: Abstract collection in property grid Pin
Robert Rohde9-Nov-06 0:52
Robert Rohde9-Nov-06 0:52 
AnswerRe: Abstract collection in property grid Pin
mark_w_9-Nov-06 1:27
mark_w_9-Nov-06 1:27 
QuestionWrapping or creating custom XML elements Pin
TUX2K8-Nov-06 23:39
TUX2K8-Nov-06 23:39 
QuestionLike "VS Watch" control Pin
El'Cachubrey8-Nov-06 23:38
El'Cachubrey8-Nov-06 23:38 
Questionhow to select data from the datagrid Pin
Saira Tanwir8-Nov-06 23:22
Saira Tanwir8-Nov-06 23:22 
AnswerRe: how to select data from the datagrid Pin
rah_sin8-Nov-06 23:45
professionalrah_sin8-Nov-06 23:45 
GeneralRe: how to select data from the datagrid Pin
Saira Tanwir9-Nov-06 0:00
Saira Tanwir9-Nov-06 0:00 
GeneralRe: how to select data from the datagrid Pin
rah_sin9-Nov-06 0:15
professionalrah_sin9-Nov-06 0:15 
AnswerRe: how to select data from the datagrid Pin
Saira Tanwir9-Nov-06 0:21
Saira Tanwir9-Nov-06 0:21 
QuestionChange Default Web Site's name of IIS Pin
lambro8-Nov-06 22:48
lambro8-Nov-06 22:48 
AnswerRe: Change Default Web Site's name of IIS Pin
TUX2K8-Nov-06 23:51
TUX2K8-Nov-06 23:51 
QuestionCreating an TWAIN ActiveX and calling it from Web Browser Pin
IndoDev8-Nov-06 22:26
IndoDev8-Nov-06 22:26 
QuestionP2P File transfers Pin
Sri harini8-Nov-06 22:23
Sri harini8-Nov-06 22:23 
AnswerRe: P2P File transfers Pin
SeMartens9-Nov-06 5:26
SeMartens9-Nov-06 5:26 
GeneralRe: P2P File transfers Pin
Sri harini9-Nov-06 16:28
Sri harini9-Nov-06 16:28 
QuestionA/V stream Pin
Mustafa Ismail Mustafa8-Nov-06 22:11
Mustafa Ismail Mustafa8-Nov-06 22:11 
QuestionHow to set Screen Resolution. Pin
Jay Khanpara8-Nov-06 22:04
Jay Khanpara8-Nov-06 22:04 

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.