how to approach Data Binding a checked Listbox?

Pulling out values and puting them in a checkedlistbox

Page 1 of 1

5 Replies - 37298 Views - Last Post: 05 April 2009 - 09:40 AM Rate Topic: -----

#1 dave1816  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 10-March 09

how to approach Data Binding a checked Listbox?

Post icon  Posted 02 April 2009 - 03:17 PM

Hi again,

Im trying to obtain values from a database into a checkedlist box, does any one have any idea how to approach this?

I currently at the moment have a datagrid which the textboxes are databinded e.g.

txtRoomNo.DataBindings.Add("Text", RD.dSet.Tables["Rooms1"], "RoomNo");

However to do this with a checked list box i believe is not possible due to it not supporting datatbinding, if i am correct from my research. Therefore i have no idea how to approach this? can any one display an example or point me in the right direction.

I only want to pull out 3 -4 values, for example, software name 1, 2, 3.

Many Thanks

D.Arnold

Is This A Good Question/Topic? 0
  • +

Replies To: how to approach Data Binding a checked Listbox?

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: how to approach Data Binding a checked Listbox?

Posted 02 April 2009 - 03:59 PM

You can databind a CheckListBox.

CheckListBox DataSource property
Was This Post Helpful? 0
  • +
  • -

#6 dave1816  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 10-March 09

Re: how to approach Data Binding a checked Listbox?

Posted 04 April 2009 - 05:47 AM

Thanks for that im getting further, i found out that intelli sence does not pick up Datasource, displaymember and value member properties for checkedlistbox, but does work when inputing them. Below is the code i used.


this.cbox_Facil_soft.DataSource = RD.dSet.Tables["Rooms1"];
this.cbox_Facil_soft.DisplayMember = "RoomNo";
this.cbox_Facil_soft.ValueMember = "RoomNo";

However the problem i have now is that the code above lists all the data(rows) in collum RoomNo, how do i limit this so that only the data displayed is an item/data from a single row selected on the datagrid?

Or i manage to come accross examples of code which display items checked from which datagrid row you select which would be a great alternative , however the example shown was a example project which files were missing.

Does anyone know or can point me in the right direction for any of the above?
Was This Post Helpful? 1

#7 searockruz  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 460
  • Joined: 07-March 09

Re: how to approach Data Binding a checked Listbox?

Posted 04 April 2009 - 05:58 AM

i am not sure what you want :blink:

either you can use where clause to limit your results to one row or

	this.cbox_Facil_soft.DataSource = RD.dSet.Tables["Rooms1"].Rows[rowno][colno];
this.cbox_Facil_soft.DisplayMember = "RoomNo";
this.cbox_Facil_soft.ValueMember = "RoomNo";
	
	

Was This Post Helpful? 0
  • +
  • -

#8 dave1816  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 6
  • Joined: 10-March 09

Re: how to approach Data Binding a checked Listbox?

Posted 04 April 2009 - 08:21 AM

Hi m8 thanks for the reply, ive never used the where clause im looking into it now, thanks but i did try the


this.cbox_Facil_soft.DataSource = RD.dSet.Tables["Rooms1"].Rows[RowNo][Column No] but i get this error message

"Complex DataBinding accepts as a data source either an IList or an IListSource" any reason why?

All i want to do is for the checkedlistbox to list the value from a single row which is select from a datagrid instead of all the values in the column which it is doing now.

Hope you understand what im taking about,lol

appreciate the reply

many thanks

D.Arnold
Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: how to approach Data Binding a checked Listbox?

Posted 05 April 2009 - 09:40 AM

You have one of two choices on how to limit your displayed value. You can either modify the SQL statement, as indicated by searockruz, using a WHERE statement.

Or you can filter the results in your dataset to only show the specific rows you need using the DefaultView property of the DataTable. Use the Filter property to specify which column you want to filter the results by and the value that you want to display. This is effectively the same as using a WHERE statement in your SQL.

DataTable.DefaultView

Replace "someColumn" with the name of the column in the dataset that you want to compare the value against and "someValueToFilterTheResultsBy" with the value from the DataGrid that was selected by the user.

Example:
RD.dSet.Tables["Rooms1"].DefaultView.Filter = "someColumn = " + someValueToFilterTheResultsBy;

this.cbox_Facil_soft.DataSource = RD.dSet.Tables["Rooms1"].DefaultView;
this.cbox_Facil_soft.DisplayMember = "RoomNo";
this.cbox_Facil_soft.ValueMember = "RoomNo";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1