Click here to Skip to main content
15,896,278 members
Home / Discussions / C#
   

C#

 
QuestionAbout Combobox's ValueMember and DisplayMember Pin
Zerox MXI5-Dec-07 20:07
Zerox MXI5-Dec-07 20:07 
GeneralRe: About Combobox's ValueMember and DisplayMember Pin
CKnig5-Dec-07 20:13
CKnig5-Dec-07 20:13 
GeneralRe: About Combobox's ValueMember and DisplayMember Pin
Zerox MXI5-Dec-07 20:23
Zerox MXI5-Dec-07 20:23 
GeneralRe: About Combobox's ValueMember and DisplayMember Pin
CKnig5-Dec-07 23:30
CKnig5-Dec-07 23:30 
GeneralRe: About Combobox's ValueMember and DisplayMember Pin
Zerox MXI6-Dec-07 3:10
Zerox MXI6-Dec-07 3:10 
Questionhow to export datagridview contents to excel Pin
Nitin Raj5-Dec-07 19:56
Nitin Raj5-Dec-07 19:56 
GeneralRe: how to export datagridview contents to excel Pin
DKalepu5-Dec-07 22:49
DKalepu5-Dec-07 22:49 
QuestionHow To : coerce a ref to an enum into a ref to an int. Pin
urbane.tiger5-Dec-07 18:59
urbane.tiger5-Dec-07 18:59 
I have a method in a common base class thus :

protected bool SetFlag(bool _new, ref int _flags, int _flag, string _pName)
{
bool __cancelled = false;
bool __old = ((_flags & _flag) == _flag);
if (!__old.Equals(_new)
{
if (!(__cancelled = this.RaisePropertyChanging(__old, _new, pName)))
{
_flags = (_new) ? _flags | _flag : _flags & ~flag;
this.RaisePropertyChanged(__old, _new, pName);
}
}
return __cancelled;
}



In derivatives of the common base I want to use SetFlags as is shown in the example at the end of this post, but I get a message telling me that it can't cast a ref to an AmbientState to an int etc.

If I give SetFlag a Type argument then I can only constrain it to a class(reference type) or struct(value type), but in that case I get compile errors stating that bitwise operations cannot be performed on T objects, ie structs.

The content of _flags (ambientState in the example) must be changed BEFORE PropertyChanged handlers are invoked.

I have a work-around - The _flags parameter is not passed by reference and I've added a delegate method argument to SetFlag that gets invoked between the "flags = ...." and the "this.RaisePropertyChanged...." statements, the delegate looks like

private void saveFlags(int _flags) { this.ambientState = (AmbientState) _flags; )

But like all workarounds its ugly and necessitates documenting why the delegate exists etc.

Rgds PhilD -- Sample usage of SetFlags follows

public class MyClass : CommonBase
{
AmbientState ambientState = AmbientState.ZeroValue;

public bool Morning
{
get { return ((this.ambientState & AmbientState.Morning) == AmbientState.Morning); }
set { this.SetFlag(value, (int) ref this.ambientState, AmbientState.Morning, "Morning"; }
}
[Flags]
private enum AmbientState : int
{
ZeroValue = 0x0

Morning = 0x1
Afternoon = 0x2
Evening = 0x4
Night = 0x8

ClearSky = 0x10
CirrusSky = 0x02
etc
}
}
AnswerRe: How To : coerce a ref to an enum into a ref to an int. Pin
Skippums6-Dec-07 10:39
Skippums6-Dec-07 10:39 
Question[Message Deleted] Pin
rockz...5-Dec-07 18:52
rockz...5-Dec-07 18:52 
GeneralRe: Serial No. for rows in datagrid Pin
Sathesh Sakthivel5-Dec-07 19:00
Sathesh Sakthivel5-Dec-07 19:00 
GeneralRe: Serial No. for rows in datagrid Pin
dan!sh 5-Dec-07 19:28
professional dan!sh 5-Dec-07 19:28 
Questionhow to populate a single column from a table to a datagridview Pin
kssknov5-Dec-07 18:46
kssknov5-Dec-07 18:46 
AnswerRe: how to populate a single column from a table to a datagridview Pin
Sathesh Sakthivel5-Dec-07 18:55
Sathesh Sakthivel5-Dec-07 18:55 
GeneralRe: how to populate a single column from a table to a datagridview Pin
kssknov5-Dec-07 19:06
kssknov5-Dec-07 19:06 
AnswerRe: how to populate a single column from a table to a datagridview Pin
I.explore.code5-Dec-07 23:49
I.explore.code5-Dec-07 23:49 
GeneralPrint data from webbrowser used on windows form Pin
D i x y5-Dec-07 18:09
D i x y5-Dec-07 18:09 
GeneralJava script using windows form Pin
Satish - Developer5-Dec-07 17:53
Satish - Developer5-Dec-07 17:53 
GeneralRe: Java script using windows form Pin
Sathesh Sakthivel5-Dec-07 17:58
Sathesh Sakthivel5-Dec-07 17:58 
GeneralRe: Java script using windows form Pin
Satish - Developer5-Dec-07 18:09
Satish - Developer5-Dec-07 18:09 
GeneralRe: Java script using windows form Pin
Sun Rays5-Dec-07 18:36
Sun Rays5-Dec-07 18:36 
GeneralA tiny issue with ".NET Snap To Screen Form" Pin
EEssam5-Dec-07 17:48
EEssam5-Dec-07 17:48 
QuestionIs it possible to record the voice from phone using tapi with C#.Net ? Pin
Gopal.S5-Dec-07 17:28
Gopal.S5-Dec-07 17:28 
AnswerRe: Is it possible to record the voice from phone using tapi with C#.Net ? Pin
Sathesh Sakthivel5-Dec-07 17:34
Sathesh Sakthivel5-Dec-07 17:34 
GeneralRe: Is it possible to record the voice from phone using tapi with C#.Net ? Pin
Gopal.S5-Dec-07 18:34
Gopal.S5-Dec-07 18:34 

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.