HighTechTalks DotNet Forums  

WinForms Databinding and NULL values

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss WinForms Databinding and NULL values in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jack Tripper
 
Posts: n/a

Default WinForms Databinding and NULL values - 05-13-2010 , 10:57 AM






Here's the scenario:

One Form that shows Employee. Employee class is as below:


class Employee {
public int EmployeeID { get;set;}
public string Name { get;set;}
public string Address { get;set;}
public int? ReportsToEmployee { get;set;}
}

The form is bound using Object Data Source with Employee class.
The idea is that I need to bind a List<Employee> to a Form. So we do this:

List<Employee> _employees = new List<Employee>(10);
_employees.Add(new Employee(....));
....

List<Employee> _managers = new List<Employee>(_employee);

employeeBindingMangaer.DataSource = _employees;
//managerComboBox.DataSource = _managers;


Now when we open the form, all is working. However if I need to specify a
reporting to for an employee as None or NULL,
I cannot do that because the displayed values are coming from database and
there is no NULL row. So one I have set this,
I cannot clear the selected choice.

I have figured the following ways:

Hack 1: Create a NULL employee object with ID=0, add to _managers and then
on value changed event, if EmployeeID is 0, set the selection to empty.
However if we will need to manually manage these null objects.


Any other way of doing this?
Can we use IExtenderControl to handle this somehow?

Any better/cleaner way? I need to do this at a lot of places in code.

Please help!

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.