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
how to approach Data Binding a checked Listbox?Pulling out values and puting them in a checkedlistbox
Page 1 of 1
5 Replies - 32403 Views - Last Post: 05 April 2009 - 09:40 AM
Replies To: how to approach Data Binding a checked Listbox?
#2
Re: how to approach Data Binding a checked Listbox?
Posted 02 April 2009 - 03:59 PM
#6
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?
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?
#7
Re: how to approach Data Binding a checked Listbox?
Posted 04 April 2009 - 05:58 AM
i am not sure what you want
either you can use where clause to limit your results to one row or
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";
#8
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
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
#9
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:
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";
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|