|
i think its better to use VC++
My small attempt...
|
|
|
|
|
I am trying to add a combo box to my C# which gets its possible values from a lookups table, but is bound to a value in a different table. I can’t quite figure out how to do this. I have two binding sources defined – one for the lookups table and one for the table which stores the value. I tried setting DataSource/DisplayMember to get the values from the lookups table and then tried to set DataBindings to the value in the other table. I tried binding Text, SelectedItem and SelectedValue, all with no luck.
This seems like it should be something easy to do, but I just can’t seem to find any examples online.
Any help would be greatly appreciated. Thanks.
|
|
|
|
|
I dont know if this will work but you could try to build up a datatable from the diferenct datasources and bind the combo box to the datatable.
|
|
|
|
|
I don't know how to do this, and I searched Google/MSDN for it also but none helped -- may be I typed in the wrong search keywords !
Anyways, what's the base type of a generic class?
E.g.
Assume I've a List<Employee>:List<T> and List<Company>:List<T> , how do I get "List" as the inner base type of List<Employee> and List<Company> ?
If I do GetType() on my _listEmployees , I get System.Collections.Generic.List`1[[Employee]] . And the base type of this type (e.g. _listEmployees.GetType().BaseType ), it is System.Object .
I'd like to use "is" keyword on my generic objects to compare them.
One more question on the "generic" declarations.
In my app, I've an abstract class called GenericValueExpression<T> and concrete classes NumericValueExpression , TextValueExpression , DateValueExpression which derive from GenericValueExpression<int> , GenericValueExpression<string> , and GenericValueExpression<DateTime> respectively.
How can I declare a collection of GenericValueExpressions?
E.g. List< GenericValueExpression<???> > _myValueExpressions ? What would go instead of ????.
Thanks for your help.
- Malhar
|
|
|
|
|
Any generic/templated class system is essentially a class factory. Without a type, the class doesn't really exist, and each type means a new class is created. The beauty of .NET is that it's created in memory, for C++, it would be created in your exe.
I'd suggest the easiest way to do your collection, is to define an interface for the common functionality, and then create a collection of that type. But, I'm not sure if that would work, if the methods take or return T, as they invariably would.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Sorry for the delayed reply. But IMO this really seems like a missing functionality in language. Simple things such as not being able to have a collection of Nullable types makes me wonder if this was intentional or something they overlooked. e.g. List<Nullable> myNullableValuesCollection = new List<Nullable>();
Here's my real requirement:
I have the following classes/interfaces:
- IDomainObject<br />
- DomainObject : IDomainObject<br />
- Employee : DomainObject<br />
- Company : DomainObject<br />
- Project : DomainObject
I've the following UI elements:
- IDataboundView <T> where T:IDomainObject<br />
- BaseView : UserControl<br />
- EmployeeManagementView : BaseView, IDataboundView<Employee><br />
- CompanyManagementView : BaseView, IDataboundView<Company><br />
- ProjectManagementView : BaseView, IDataboundView<Project>
In the BaseView's load method, I'd like to be able to do something like ...
void OnLoad(..)
{
if (this is IDataboundView)
{
Get the generic type parameter for the IDataboudView (e.g. Employee, Company, Project...)
Get the list of IDomainObjects (e.g. EmployeeColl/CompanyColl/ProjectColl etc)
Call the IDataboundView's method for "this" instance and set the collection
}
}
But I cannot achieve the above. Do you have any suggestions?
|
|
|
|
|
What you can do is have an instance of T as a member variable, and use 'is' on that.
C++ templates were certainly more powerful, but, realistically, most people used them in the ways that generics are now used.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 All,
I am working on a MCMS page with a dropdown list of all the existing posting Name. The page will render a "preview" of the page depend on the dropdown value. Could someone tell me how to work this out? Thanks in advance
gsdg
|
|
|
|
|
Good People,
I need to cast from my class to a native data type. For example: int payRate = MyNumberObject. How do I do that? Also, how do I build my class such that it can be interchangeable with the native numeric types.
Any information or a link to some information would be great.
Thanks,
BP
|
|
|
|
|
BlitzPackage wrote: I need to cast from my class to a native data type.
And ?
BlitzPackage wrote: int payRate = MyNumberObject
int payRate = MyNumberObject as int;
od
int payrate = (int)MyNumberObject;
Inherit your class from that type.
BlitzPackage wrote: interchangeable with the native numeric types.
|
|
|
|
|
LongHC wrote: int payRate = MyNumberObject as int;
You can't as a value type.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"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 )
|
|
|
|
|
Sorry, my fault, thanks for correcting me.
|
|
|
|
|
Hey!
LongHC wrote: int payRate = MyNumberObject as int;
you can't use 'as' operator with value type classes :/ only reference type..
life is study!!!
|
|
|
|
|
Hi,
AFAIK this is not possible.
You can implement implicit casting from some value type such as int to your type,
but not the other way around.
But you can provide a method to do the conversion, someting similar to
ToString() which exists for all objects, and ToInt32() which exists for
some classes (e.g. IntPtr).
|
|
|
|
|
yes you can, try this:
public class MyClass
{
private int m_width;
public int Width
{
get { return m_width; }
set { m_width = value; }
}
public static implicit operator int (MyClass source)
{
int output = source == null ? 0 : source.Width;
return output;
}
public void Test()
{
int value = this;
Console.WriteLine(value);
}
}
a peruvian programmer
|
|
|
|
|
You are right of course, dont know what I was thinking here.
|
|
|
|
|
i tend to err on the side of caution and use:
public static explicit operator int(MyClass source)
Russ
|
|
|
|
|
Is there a standard .NET object that abstracts version information (at minimum, major, minor, edit and build numbers)?
/ravi
|
|
|
|
|
You could use System.Diagnostics.FileVersionInfo, it gives you all the information your looking for.
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
|
|
|
|
|
Thanks! I knew there had to be something!
/ravi
|
|
|
|
|
|
Even better - many thanks!
Which begs the question: why didn't it show up in my Google and MSDN search?
/ravi
|
|
|
|
|
Hello,
i pinvoke a function from an com api. The function needs two parameters, an com interface and one out parameter. The prototype from the function is
BOOL WINAPI theFunc(theObject* pObject, LPTSTR szName);
My Call
<br />
[System.Runtime.InteropServices.DllImport("mydll.dll")]<br />
static extern unsafe bool theFunc([MarshalAs(UnmanagedType.Interface)] theItem item, StringBuilder buffer);<br />
<br />
StringBuilder buffer = new StringBuilder(1024);<br />
try<br />
{<br />
bRet = teFunc(_o, buffer);<br />
}...<br />
In a normal Windows Application there is no error. The error occured only when i use the code in a c# Windows service. The exception is that the memory might be damaged... AccessViolationException
Any ideas?
-- modified at 14:54 Monday 16th April, 2007
|
|
|
|
|
realmontanakid wrote: Any ideas?
How is native code going to be able to use a StringBuilder object?
led mike
|
|
|
|
|
Mike, this is standard procedure when passing in strings into functions that are expected to modify the string.
|
|
|
|