Binding Combobox

  • Thread starter Thread starter Luis Soler
  • Start date Start date
L

Luis Soler

Hi:

I have following binding with a combobox in my form:

cboActividad.DataBinding.Add("SelectedItem",dtTable,"activity")
dtTable.Columns("activity").DefaultValue = ""

However, when I test changes in Dataset with Haschanges Method, it always
returns True.

Why ?
I don't know if I must set some additional option.
 
That's expected. SelectedItem does not have corresponding
SelectedItemChanged event on NETCF.

That means data binding engine would always push data from control to data
source even if data never changed.


Best way to solve this problem would be to extend CB with
SelectedItemChanged event.

Same is applicable to any property without corresponding Changed event -
binding to it would instantly change data source.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
I would do something like this (untested):

public class ComboBoxEx : ComboBox

{

public event EventHandler SelectedItemChanged;


public ComboBoxEx() : base()

{

// Nothing

}

protected override void OnSelectedIndexChanged(EventArgs e)

{

base.OnSelectedIndexChanged(e);

if (this.SelectedItemChanged != null)

this.SelectedItemChanged(this, e);

}

}


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Hi Ilya:

Now, I get error: "An unhandled exception of type "System.ArgumentException"
occurred in mscorlib.dll" at statement:
cboActividad.DataBinding.Add("SelectedItem",dtTable,"activity")

cboActivitidad is ComboBoxEx type.
dtTable is Datatable:
Dim dtTable as DataTable = dsTable.Tables("customers")

It seems that wrong argument is: dtTable but I don't Know why.
 
Does that work without event for normal CB? If yes, you need to debug this
new event to make sure it fires correctly.

If normal CB does not work, you have issues in other areas. May be there's
no column "activity" for example or dtTable is null.

Also, it might matter what are the items in the CB.


Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

Luis Soler said:
Hi Ilya:

Now, I get error: "An unhandled exception of type
"System.ArgumentException" occurred in mscorlib.dll" at statement:
cboActividad.DataBinding.Add("SelectedItem",dtTable,"activity")

cboActivitidad is ComboBoxEx type.
dtTable is Datatable:
Dim dtTable as DataTable = dsTable.Tables("customers")

It seems that wrong argument is: dtTable but I don't Know why.



Ilya Tumanov said:
I would do something like this (untested):

public class ComboBoxEx : ComboBox

{

public event EventHandler SelectedItemChanged;


public ComboBoxEx() : base()

{

// Nothing

}

protected override void OnSelectedIndexChanged(EventArgs e)

{

base.OnSelectedIndexChanged(e);

if (this.SelectedItemChanged != null)

this.SelectedItemChanged(this, e);

}

}


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

Luis Soler said:
Where can I find an example to build SelectedItemChanged event ?

Regards.

"Ilya Tumanov [MS]" <[email protected]> escribió en el
mensaje That's expected. SelectedItem does not have corresponding
SelectedItemChanged event on NETCF.

That means data binding engine would always push data from control to
data source even if data never changed.


Best way to solve this problem would be to extend CB with
SelectedItemChanged event.

Same is applicable to any property without corresponding Changed
event - binding to it would instantly change data source.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no
rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

Hi:

I have following binding with a combobox in my form:

cboActividad.DataBinding.Add("SelectedItem",dtTable,"activity")
dtTable.Columns("activity").DefaultValue = ""

However, when I test changes in Dataset with Haschanges Method, it
always returns True.

Why ?
I don't know if I must set some additional option.
 
Back
Top