 |
|
 |
the given link included a windows appilcation,i need same like in web application ,any codeproject avialble
Please give me a help
|
|
|
|
 |
|
 |
Note that even the DataSource, DisplayMember and ValueMember properties don't show up in VS's intellisense, they are there.
......
......
anyDataSet globalDataSet = new anyDataSet();
CheckedListBox myChkListBox = new CheckedListBox();
.....
private void fillCheckedListBox()
{
anyDataSetTableAdapters.myTableTableAdapter ta = new anyDataSet TableAdapters.myTableTableAdapter();
ta.Fill(globalDataSet.myTable);
myChkListBox .DataSource = globalDataSet.myTable;
myChkListBox .DisplayMember = "myDisplayMember";
myChkListBox .ValueMember = "myValuMember";
myChkListBox .BindingContext = new BindingContext(); //This is the important part
}
|
|
|
|
 |
|
 |
Alejandro,
This solution is much simpler, but I'd like to know somethings from you:
1. What's the role of BindingContext in this code?
2. If you set the DataSource after the Display and Value members you also get an inconsistency in the displayed text? I tried with CheckedListBox and the custom one presented in this article, and both have this bug. Using ListBox, though, everything works fine. I tried to find out what's the difference between the implementation of ListBox and CheckedListBox but I counldn't get it. I believe there is some kind of event being raised after the regular code flow.
Both questions are important because I wouldn't like to teach my team how to make a "special bind" for one specific control, so, I'd rather create my own full functional control.
Thank you in advance.
Filipe
|
|
|
|
 |
|
 |
Just what I was looking for. Thanks
|
|
|
|
 |
|
 |
In databound mode this listbox appears to reset its Value property to 0 (zero) so all checked items appear unchecked if you call Dataset.AcceptChanges or Datatable.AcceptChanges in either the form's Load event or the form's Shown event.
|
|
|
|
 |
|
 |
Hi
I have CheckListBox In ASP 2005 By VB How I Can Retrieve Selected Data From DataBase
In Data Base I Have Three table
1- School
-School_Code
-School_Desc
2-Order
-Order_Code
-Order_Desc
3-OrdAndScho
-Order_Code
-School_Desc
One School Have One Or More Order
I Can insert the Value To The DataBase, But I Can’t Retrieve Please Help Me as soon As Possible
Note, I’m using SqlServer Data Base
Thanks
|
|
|
|
 |
|
 |
CheckedListBox does have Datasource, DisplayMember properties.
It just doesn't show up in Intellisense.
I have used below code and it is working.
FieldValuesListBox.DataSource = ds.Tables(0)
FieldValuesListBox.DisplayMember = "Department"
VB Prog
|
|
|
|
 |
|
 |
Thanks! It was very usefull your post!
|
|
|
|
 |
|
 |
Hi,
Thank you it is very userful
|
|
|
|
 |
|
 |
If you just need the binding related properties, simply cast your CheckedListBox into ListBox. Since CheckedListBox inherits from ListBox, it will work. After the cast set the binding related properties and that's it. You can do all of this in the form load handler.
Of course your solution is more readable (which is great), but it requires sub-classing for a very simple problem.
I wonder why Microsoft have hidden these properties...
|
|
|
|
 |
|
 |
Can you provide an example of how to accomplish what you describe here?
Thanks
|
|
|
|
 |
|
 |
This is not a complete working example, but you can get the idea.
public partial class Form1 : Form
{
Shay.
|
|
|
|
 |
|
 |
Should be of course:
private BindingList<Fruit> _fruitsDs = new BindingList<Fruit>();
Haven't notice the HTML editor removed my <>...
|
|
|
|
 |
|
 |
Hi, I like your solution to make the checkedlistbox bindable.
But if I understand correctly, your example is expecting a bitwise coded relation between the two tables. This is very nasty for a simple relational database application. Do you have a tip or solution for this?
Or did miscrosoft already solve this for us?
thankx, edgar
epuy@xs4all.nl
|
|
|
|
 |
|
 |
it is a very good work
thank you
abdel rahman
|
|
|
|
 |
|
 |
I was really pleased when I found this article. I was trying to create a similar control, and had followed quite a similar approach but missed a couple of things.
I still seem to be having a problem though - Something really weird is happening. As soon as I have tabbed into or clicked on the control, I cannot seem to get out of it again.
It seems to still be working, but everything else, including the form it is on is locked up.
Has anyone else seen this (and hopefully resolved it)?
|
|
|
|
 |
|
 |
I just can get the text in the selected items. But i need to get the VALUE of the checked item that set int the databinding.
May you help me?
|
|
|
|
 |
|
 |
Hi,
I didn't test it or anything, so i may be totally wrong. But i have this idea that passing an array or a list of object as the single bound property (Value) would do the job in a more transparent way? The elements of the array would then be the selected items (or their ValueMember properties).
Also, i think that implementing the Value property of the control as IEnumerable or IList would allow the bound object to implement its binding property in any specialized way. So you should not be forced to use something generic as object[] or List<object>.
But again, i haven't tested my idea. And it's a nice article anyway.
Grtz,
Phil
Philippe Dykmans
Software developpement
University of Antwerp
|
|
|
|
 |
|
 |
this is a good idea
but describe me more please
regards
eraghi
|
|
|
|
 |
|
 |
Hello Eraghi,
As i was trying my idea in a separate project, turned out that there are a few problems i didn't immediately think of
As i said, i didn't test it before. I'm gonna do a bit more thinking and trying on this. Will be back soon!
Regards,
Philippe
Philippe Dykmans
Software developpement
University of Antwerp
|
|
|
|
 |
|
 |
First of thanks for the great article - it really helped me to have a control I needed.
I've converted the code to VB (I used 2005 Express, but the code will probably work in previous versions, but I haven't tested that), and added a few properties.
I noticed you left out ValueMember, so I added that in as otherwise the SelectedValue property doesn't work.
I also added SelectedValues and CheckedValues to return arrays of the Selected/Checked values as determined by the ValueMember.
Imports System.ComponentModel
Imports System.Drawing.Design
Public Class ExCheckedListBox
Inherits CheckedListBox
Private _value As Integer
Public Property Value() As Integer
Get
Try
Dim poweredNumber As Integer = 1
For i As Integer = 0 To Me.Items.Count - 1
If Me.GetItemChecked(i) Then
Me._value = Me._value Or poweredNumber
ElseIf Me._value And poweredNumber <> 0 Then
Me._value -= poweredNumber
End If
poweredNumber *= 2
Next
Catch ex1 As ArgumentException
Throw ex1
Catch ex As Exception
Throw ex
End Try
Return Me._value
End Get
Set(ByVal value As Integer)
Me._value = value
Try
Dim poweredNumber As Integer = 1
For i As Integer = 0 To Me.Items.Count - 1
If Me._value And poweredNumber <> 0 Then
Me.SetItemCheckState(i, CheckState.Checked)
Else
Me.SetItemCheckState(i, CheckState.Unchecked)
End If
poweredNumber *= 2
Next
Catch ex1 As ArgumentException
Throw ex1
Catch ex As Exception
Throw ex
End Try
End Set
End Property
<DefaultValue(""), AttributeProvider(GetType(IListSource)), RefreshProperties(RefreshProperties.All), Browsable(True)> _
Public Shadows Property DataSource() As Object
Get
Return MyBase.DataSource
End Get
Set(ByVal value As Object)
MyBase.DataSource = value
End Set
End Property
<DefaultValue(""), _
TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), _
Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), _
Browsable(True)> _
Public Shadows Property DisplayMember() As String
Get
Return MyBase.DisplayMember
End Get
Set(ByVal value As String)
MyBase.DisplayMember = value
End Set
End Property
<DefaultValue(""), _
TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), _
Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor)), _
Browsable(True)> _
Public Shadows Property ValueMember() As String
Get
Return MyBase.ValueMember
End Get
Set(ByVal value As String)
MyBase.ValueMember = value
End Set
End Property
<Browsable(False)> _
Public ReadOnly Property SelectedValues() As Array
Get
Dim i As Integer = -1
Dim ret() As Object = Nothing
For Each idx As Integer In Me.SelectedIndices
i += 1
ReDim Preserve ret(i)
ret(i) = CType(MyBase.DataManager.List.Item(idx), DataRowView).Item(Me.ValueMember)
Next
Return ret
End Get
End Property
<Browsable(False)> _
Public ReadOnly Property CheckedValues() As Array
Get
Dim i As Integer = -1
Dim ret() As Object = Nothing
For Each idx As Integer In Me.CheckedIndices
i += 1
ReDim Preserve ret(i)
ret(i) = CType(MyBase.DataManager.List.Item(idx), DataRowView).Item(Me.ValueMember)
Next
Return ret
End Get
End Property
End Class
Thanks again!
|
|
|
|
 |
|
 |
Thanks for this vb sample of a databound CheckedListBox, and thanks to Hossein eraghi for the initial post.
I have taken the code from the vb conversion and created my own ExtendedCheckedListbox control. However whenI have finished populating it the ValueMember stored the correct value (a unique integer for the datarow) but the DisplayMember doesn't and instead of the text for the list items I get "System.Data.DataRowView" for each item?
I have created a textbox to get the Value and Text of the SelectedItem and while the value changes the text does not.
Do you have any idea whats going on, because I don't?
Dim strSQL As String
strSQL = "SELECT tccRoles.RoleID, tccRoles.RoleName FROM tccSiteRoles WHERE tccRoles.SiteID = 1"
Using oSQLConn As New SqlConnection(ConfigurationManager.ConnectionStrings("tccDataStore").ConnectionString)
Using oDA As New SqlDataAdapter(strSQL, oSQLConn)
oDA.Fill(oDSet, "SiteRoles")
End Using
End Using
ExchkListRoles.ValueMember = oDSet.Tables("SiteRoles").Columns("RoleID").ColumnName
ExchkListRoles.DisplayMember = oDSet.Tables("SiteRoles").Columns("RoleName").ColumnName
ExchkListRoles.DataSource = oDSet.Tables("SiteRoles")
Karl
|
|
|
|
 |
|
 |
Great effort on porting to VB.NET but it will not compile with option explict on and option strict on. It is always best to turn both on so there are no assumsions to what the code will do.
Kevin S. Gallagher
Programming is an art form that fights back
|
|
|
|
 |
|
 |
it is always returning
"System.Data.DataRowView"
please help
thanks
|
|
|
|
 |
|
 |
Hello, try this:
for (int i = 0; i < chkBoxListCategory.Items.Count; i++)
{
foreach (DataRow dtrCategory in ocomdrop.DTCategory.Rows)
{
string x = chkBoxListCategory.GetItemText(chkBoxListCategory.Items[i]);
bool y = chkBoxListCategory.GetItemChecked(i);
if (dtrCategory["CategoryName"].ToString() == x & y)
{
MessageBox.Show(y.ToString());
}
}
}
Bye, Christopher.
-- modified at 16:18 Wednesday 29th November, 2006
|
|
|
|
 |