Click here to Skip to main content
16,016,500 members
Home / Discussions / C#
   

C#

 
GeneralRe: Capturing messeges from other program Pin
OsoreWatashi28-Dec-07 3:45
OsoreWatashi28-Dec-07 3:45 
General[Message Deleted] Pin
eyeseetee19-Dec-07 1:02
eyeseetee19-Dec-07 1:02 
GeneralRe: strange problem with stored procedure Pin
Pete O'Hanlon19-Dec-07 1:18
mvePete O'Hanlon19-Dec-07 1:18 
GeneralRe: Deleted Message Pin
Paul Conrad24-Dec-07 19:44
professionalPaul Conrad24-Dec-07 19:44 
QuestionC#:Doubt in event handler? Pin
kssknov19-Dec-07 0:14
kssknov19-Dec-07 0:14 
GeneralRe: C#:Doubt in event handler? Pin
Giorgi Dalakishvili19-Dec-07 0:25
mentorGiorgi Dalakishvili19-Dec-07 0:25 
GeneralRe: C#:Doubt in event handler? Pin
Xmen Real 19-Dec-07 3:41
professional Xmen Real 19-Dec-07 3:41 
GeneralEntering null values from ComboBox Pin
AndrusM18-Dec-07 23:57
AndrusM18-Dec-07 23:57 
I want to create nullable combobox whuch stores null to datasource when Text
is empty and null value is not in ComboBox Item list.

I tried the code below but null is not stored to s.CustId.
How to change this code so that null is stored to s.CustId ?

It it possible to store null without adding null entity to Customer class ?
I have generic ComboBox which allows to select foreign keys from Customer,
Product etc.
lists.
Generic code to instantiate and add null Id to every such objects seems to
be compilated.
In every list Id and Name propetries have different names, eq. names may be
productname, customername, productcode, customervatno etc.
So I must use CreateInstance to create empty entity object and then use
reflection to set id property to null and foreign key property to empty
string.
This seems to be complicated. So I'm looking for a simpler way to allow
Combobox natively support this.

Andrus.


using System.Windows.Forms;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
<br />
class testForm : Form {<br />
<br />
Storage s = new Storage();<br />
<br />
testForm() {<br />
<br />
Customer c = new Customer();<br />
c.Id = "J";<br />
c.Name = "John";<br />
List<Customer> l = new List<Customer>();<br />
l.Add(c);<br />
<br />
NullableComBobox cm = new NullableComBobox();<br />
cm.DisplayMember = "Name";<br />
cm.ValueMember = "Id";<br />
cm.DataSource = l;<br />
<br />
s.CustId = "J";<br />
cm.DataBindings.Add("SelectedValue", s, "CustId");<br />
<br />
Controls.Add(cm);<br />
Button b = new Button();<br />
b.Top = 80;<br />
b.Click += new System.EventHandler(b_Click);<br />
Controls.Add(b);<br />
}<br />
<br />
void b_Click(object sender, System.EventArgs e) {<br />
<br />
if (s.CustId == null)<br />
MessageBox.Show("Value is null");<br />
else<br />
MessageBox.Show("Value is NOT null "+s.CustId.ToString());<br />
}<br />
<br />
class Customer {<br />
public string Id { get; set; }<br />
public string Name { get; set; }<br />
}<br />
<br />
class Storage {<br />
public string CustId { get; set; }<br />
}<br />
<br />
static void Main() {<br />
Application.Run(new testForm());<br />
}<br />
}<br />
<br />
/// <summary><br />
/// Combobx which stores null value for empty Text.<br />
/// </summary><br />
public class NullableComBobox : ComboBox {<br />
<br />
protected override void OnValidating(CancelEventArgs e) {<br />
<br />
if (Text.Trim().Length == 0) {<br />
SelectedIndex = -1;<br />
base.OnValidating(e);<br />
return;<br />
}<br />
<br />
int pos = FindString(Text.Trim());<br />
<br />
if (pos >= 0) {<br />
SelectedIndex = pos;<br />
base.OnValidating(e);<br />
return;<br />
}<br />
<br />
e.Cancel = true;<br />
MessageBox.Show("Invalid entry");<br />
base.OnValidating(e);<br />
}<br />
} 

Andrus

QuestionC#: How to change the color of a disabled textbox? Pin
kssknov18-Dec-07 22:45
kssknov18-Dec-07 22:45 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Pete O'Hanlon18-Dec-07 23:02
mvePete O'Hanlon18-Dec-07 23:02 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
kssknov19-Dec-07 0:12
kssknov19-Dec-07 0:12 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Paul Conrad24-Dec-07 19:47
professionalPaul Conrad24-Dec-07 19:47 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Pete O'Hanlon19-Dec-07 0:51
mvePete O'Hanlon19-Dec-07 0:51 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Kalvin @ Work19-Dec-07 3:17
Kalvin @ Work19-Dec-07 3:17 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Xmen Real 19-Dec-07 3:47
professional Xmen Real 19-Dec-07 3:47 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
V.19-Dec-07 4:26
professionalV.19-Dec-07 4:26 
GeneralRe: C#: How to change the color of a disabled textbox? Pin
Dan Neely19-Dec-07 5:00
Dan Neely19-Dec-07 5:00 
GeneralArray list implementation in .Net Framework Pin
King Shez18-Dec-07 22:37
King Shez18-Dec-07 22:37 
GeneralRe: Array list implementation in .Net Framework Pin
Giorgi Dalakishvili18-Dec-07 22:46
mentorGiorgi Dalakishvili18-Dec-07 22:46 
GeneralRegular expression - problem! Pin
Kolo18-Dec-07 21:39
Kolo18-Dec-07 21:39 
GeneralCrystal report Pin
wasimsharp18-Dec-07 21:24
wasimsharp18-Dec-07 21:24 
QuestionHow to use a Enterpise Task Custom Field with C# (Project Server 2007) Pin
RobertSoelner18-Dec-07 21:15
RobertSoelner18-Dec-07 21:15 
GeneralRe: How to use a Enterpise Task Custom Field with C# (Project Server 2007) Pin
Paul Conrad22-Dec-07 9:19
professionalPaul Conrad22-Dec-07 9:19 
GeneralRe: How to use a Enterpise Task Custom Field with C# (Project Server 2007) Pin
RobertSoelner22-Dec-07 22:37
RobertSoelner22-Dec-07 22:37 
GeneralRe: How to use a Enterpise Task Custom Field with C# (Project Server 2007) Pin
Paul Conrad24-Dec-07 19:46
professionalPaul Conrad24-Dec-07 19:46 

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.