Search Results

Search found 21 results on 1 pages for 'checkedlistbox'.

Page 1/1 | 1 

  • populating one checkedlistbox with another (checkedlistbox)

    - by 8thWonder
    I am having difficulties populating a checkedlistbox (CLB) based on the selection(s) made in another. It should also be noted that I have a "Select All" checkbox at the top that checks/unchecks all of the items in the first CLB. Here's the code: Private Sub chkSelectAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSelectAll.CheckedChanged For i As Integer = 0 To clb1.Items.Count - 1 clb1.SetItemChecked(i, chkSelectAll.Checked) Next End Sub Private Sub clb1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clb1.ItemCheck Dim i As Integer = clb1.SelectedIndex For j As Integer = 0 To al_2.Count - 1 If i = -1 Then For k As Integer = 0 To al_2.Count - 1 If Not clb2.Contains(al_2(k).sDate) Then clb2.Items.Add(al_2(k).sDate) Else : k += 1 End If Next ElseIf (e.NewValue = CheckState.Checked And al_2(j).sName = al_1(i)) Then clb2.Items.Add(al_2(j).sDate) ElseIf (e.NewValue = CheckState.Unchecked And al_2(j).sName = al_1(i)) Then clbProdBkups.Items.Remove(al_2(j).sDate) End If Next End Sub The first CLB is populated with an arraylist of values on the button click event. Based on whatever is checked in the first CLB, corresponding values from an arraylist of structures should fill the second CLB. The following code partially works until the "Select All" checkbox is clicked at which point one of two things happens: If other values have been selected before "Select All" is checked, the second CLB is filled with the correct number of corresponding values BUT only those of the most recently selected item of the first CLB instead of all of corresponding values of all of the items that were not already selected. When "Select All" is unchecked, the most recently incorrect values are removed, everything in CLB 1 is unchecked but the values in CLB 2 that were selected before "Select All" was checked remain. If "Select All" is checked before anything else is selected, I get an "unable to cast object of type 'System.String' to type 'System.Windows.Forms.Control'" error that points to the following statement from the itemcheck event: If Not clb2.Contains(al_2(k).sDate) Then Any insights will be greatly appreciated. ~8th

    Read the article

  • LB_SETTABSTOPS does not appear to affect a CheckedListBox

    - by BP
    I am trying to set tab stops in a CheckedListBox in my WinForms application, but no matter what I do, it does not seem to have any effect. I have the following in the code for my form: <DllImport("user32.dll")> _ Public Sub SendMessage(ByVal hWnd As IntPtr, ByVal uMsg As Int32, ByVal wParam As Int32, ByRef lParam As Int32) End Sub Public Const LB_SETTABSTOPS As Int32 = &H192 And in the form's load method, I am doing the following, where theList is my CheckedListBox: Dim tabStops() As Integer = {40, 140, 240} Call SendMessage(theList.Handle, LB_SETTABSTOPS, tabStops.Length, tabStops(0)) theList.Refresh() And then later on, I use this in a loop, where col1 through col4 are all string values for the columns: theList.Items.Add(col1 & vbTab & col2 & vbTab & col3 & vbTab & col4) But no matter what I use for the values of tabStops, the list is formatted with standard width tab stops.

    Read the article

  • Check item in CheckedListBox without selecting

    - by Dmi
    How can I allow the user to click to check an item in CheckedListBox in one click? The default behaviour is the first click selects the item, the second click allows you to toggle the check. I don't want to toggle the check on select either, I'm looking for the behavior of the ListView control where I can click directly on check boxes to toggle them without selecting their items first.

    Read the article

  • For each <item> in CheckedListBox. <item> returns as Object and not as Control

    - by Tivie
    Hello there. I have a CheckedListBox previously populated. I want to loop with a "for each / next" through all items in the CheckedListBox and do a lot of "stuff" with each iteration element of the checkedlistbox. example code: For Each item In CheckedListBox1.Items If item.Checked = True Then 'do stuff like item.BackColor = Color.Blue Else 'do other stuff item.BackColor = Color.Brown End If Next the problem is that is an 'Object' type and not a 'Control' type. If I force the iteration var As CheckBox, it throws an InvalidCastException saying that type 'System.String' can't be associated with type 'System.Windows.Forms.CheckBox' I know I can easily work around using for i=0 to CheckedListBox.Items.Count - 1 but I want to use a for each /next loop since I have a lot of code in that loop (and With can't be used) and always poiting directly to the object is something I wish to avoid and I really need the code to be as simple as possible. I actually spent one afternoon looking for this but couldn't find any answer. If someone could be kind enough to enlight me in this, it would be extremely appreciated. Best regards

    Read the article

  • How to add a margin to a CheckedListBox in .NET?

    - by Xanatos
    I'm writing an windforms application using .NET (actually IronPython, but that's not relevant), and I have a CheckedListBox object in my GUI. It's working fine, it has about 20 items in a multicolumn layout. But I can't figure out how to give the thing a nice internal margin--I want to insert around 20 or 30 pixels of whitespace around the top, bottom, left, and right edges of the checkboxes. To be clear, I want the whitespace to appear between the border of the CheckedListBox and the Checkboxes inside it, not outside the whole component. Hopefully this is an easy answer, and I'm just missing it cause I'm new to programming in windows. If its not possible, I guess that'd be good to know too, so I don't waste anymore time with it. (If I were doing this in Swing (Java) I would be looking to set the Insets on my component, or maybe build up a compound border with some empty space in it.)

    Read the article

  • Count checked CheckedListBox items

    - by comii
    Hi! I have CheckedListBox and four item in it! Now I want to count number of checked item. For this I use: countnumber=CheckedListBox1.CheckedItems.Count But countnumber is always 0 even if I checked CheckedListBox items or not! What I am doing wrong?

    Read the article

  • Clone a DataBound Checked List Box

    - by Buddhi Dananjaya
    Hi I have a DataBound CheckedListBox, I "check" few items on list box(source), then I need to clone it to new Checked List Box(target). It need to have all the data, with checked state. I have tried with following function. It is properly flowing through this function. But finally I can see items on target CheckedListBox but none of the items in target is checked. private void CloneCheckedListBox(CheckedListBox source, CheckedListBox target) { foreach (int checkedItemIndex in source.CheckedIndices) { target.SetItemChecked(checkedItemIndex, true); } } Edit: I have a User control which I have placed on a TabPage, on that User Control there is a "CheckedListBox", I do need to create a new TabPage with the user entered value on selected(current) TabPage(on User Control) So, what I have done is, create a new Tab Page, get a Copy of the User Control calling it's "Clone()" method. In "Clone()" method need to have CheckedListBox cloning feature. Here is my Cloning Code, which is on User Control... public SearchMain Clone() { SearchMain smClone = new SearchMain(); smClone.txtManufacturers.Text = this.txtManufacturers.Text; smClone.udPriceFrom.Value = this.udPriceFrom.Value; smClone.udPriceTo.Value = this.udPriceTo.Value; smClone.chkOld.Checked = this.chkOld.Checked; smClone.chkPrx.Checked = this.chkPrx.Checked; smClone.chkDisc.Checked = this.chkDisc.Checked; smClone.chkStock.Checked = this.chkStock.Checked; smClone.chkFirstDes.Checked = this.chkFirstDes.Checked; smClone.chkFirstPN.Checked = this.chkFirstPN.Checked; smClone.txtSuppPN.Text = this.txtSuppPN.Text; smClone.txtManuPN.Text = this.txtManuPN.Text; smClone.txtManufacturers.Text = this.txtManufacturers.Text; smClone.meDesAND.Text = this.meDesAND.Text; smClone.meDesOR.Text = this.meDesOR.Text; smClone.meDesNOT.Text = this.meDesNOT.Text; smClone.lbManufacSelected.Items.AddRange(this.lbManufacSelected.Items); smClone.lbSearchWithIn.Items.AddRange(this.lbSearchWithIn.Items); **CloneCheckedListBox(this.clbLang, smClone.clbLang);** // CloneCheckedListBox(this.clbTypes, smClone.clbTypes); return smClone; }

    Read the article

  • Images next to the checkbox in CheckedListBox

    - by comii
    Hi! I have CheckedListBox, now i want to put image from the ImageList next to the every checkbox. I try to do that with this: CheckedListBox1.Items.Add(ImageList1.Images(0)) But with this I get only checkbox with text System.Drawing.Bitmap! What I am doing wrong, I and how i can put image next to the checkbox? Thanks!

    Read the article

  • VB.NET: how to require CheckedListBox to have at least one item selected in WinForms

    - by Craig Johnston
    With the CheckListBox in VB.NET in VS2005, how would you make it compulsory that at least one item is selected? Can you select one of the items at design time to make it the default? EDIT: How can I make it so the last item the user tries to uncheck is the one that stays checked? So it's like the user tries to uncheck the only checked item but can't because it checks back straightaway.

    Read the article

  • how to check only one item in checkedlistbox

    - by Shashi Jaiswal
    I have check list box control and i want to select only one item at a time and i am currently using this code to do the same. private void CLSTVariable_ItemCheck(object sender, ItemCheckEventArgs e) { // Local variable int ListIndex; CLSTVariable.ItemCheck -= CLSTVariable_ItemCheck; for (ListIndex = 0; ListIndex < CLSTVariable.Items.Count; ListIndex++) { // Unchecked all items that is not currently selected if (CLSTVariable.SelectedIndex != ListIndex) { // set item as unchecked CLSTVariable.SetItemChecked(ListIndex, false); } // if else { // set selected item as checked CLSTVariable.SetItemChecked(ListIndex, true); } } // for CLSTVariable.ItemCheck += CLSTVariable_ItemCheck; } this code is working fine. but problem is that when i click again and again on selected item then that selected item should not be unchecked, means at least one item should be checked always...

    Read the article

  • c# event fires windows form incorrectly

    - by MikeW
    I'm trying to understand what's happening here. I have a CheckedListBox which contains some ticked and some un-ticked items. I'm trying to find a way of determining the delta in the selection of controls. I've tried some cumbersome like this - but only works part of the time, I'm sure there's a more elegant solution. A maybe related problem is the myCheckBox_ItemCheck event fires on form load - before I have a chance to perform an ItemCheck. Here's what I have so far: void clbProgs_ItemCheck(object sender, ItemCheckEventArgs e) { // i know its awful System.Windows.Forms.CheckedListBox cb = (System.Windows.Forms.CheckedListBox)sender; string sCurrent = e.CurrentValue.ToString(); int sIndex = e.Index; AbstractLink lk = (AbstractLink)cb.Items[sIndex]; List<ILink> _links = clbProgs.DataSource as List<ILink>; foreach (AbstractLink lkCurrent in _links) { if (!lkCurrent.IsActive) { if (!_groupValues.ContainsKey(lkCurrent.Linkid)) { _groupValues.Add(lkCurrent.Linkid, lkCurrent); } } } if (_groupValues.ContainsKey(lk.Linkid)) { AbstractLink lkDirty = (AbstractLink)lk.Clone(); CheckState newValue = (CheckState)e.NewValue; if (newValue == CheckState.Checked) { lkDirty.IsActive = true; } else if (newValue == CheckState.Unchecked) { lkDirty.IsActive = false; } if (_dirtyGroups.ContainsKey(lk.Linkid)) { _dirtyGroups[lk.Linkid] = lkDirty; } else { CheckState oldValue = (CheckState)e.NewValue; if (oldValue == CheckState.Checked) { lkDirty.IsActive = true; } else if (oldValue == CheckState.Unchecked) { lkDirty.IsActive = false; } _dirtyGroups.Add(lk.Linkid, lk); } } else { if (!lk.IsActive) { _dirtyGroups.Add(lk.Linkid, lk); } else { _groupValues.Add(lk.Linkid, lk); } } } Then onclick of a save button - I check whats changed before sending to database: private void btSave_Click(object sender, EventArgs e) { List<AbstractLink> originalList = new List<AbstractLink>(_groupValues.Values); List<AbstractLink> changedList = new List<AbstractLink>(_dirtyGroups.Values); IEnumerable<AbstractLink> dupes = originalList.ToArray<AbstractLink>().Intersect(changedList.ToArray<AbstractLink>()); foreach (ILink t in dupes) { MessageBox.Show("Changed"); } if (dupes.Count() == 0) { MessageBox.Show("No Change"); } } For further info. The definition of type AbstractLink uses: public bool Equals(ILink other) { if (Object.ReferenceEquals(other, null)) return false; if (Object.ReferenceEquals(this, other)) return true; return IsActive.Equals(other.IsActive) && Linkid.Equals(other.Linkid); }

    Read the article

  • How can I work with the Tag property of a winforms checked listbox item?

    - by JMSA
    How can I write a C# winforms code like this? CheckedListBox items don't have 'Tag' and 'ValueMember' properties. I know there are many alternatives to this. But I need to work it this way. private void LoadPermissionsToCheckedListBox() { Role selctedRole = (Role)comboBox1.SelectedItem; int i = 0; foreach (Permission p in selctedRole.PermissionItems) { checkedListBox1.Items.Add(p); checkedListBox1.Items[i].Tag = p; } checkedListBox1.DisplayMember = "PermissionKey"; checkedListBox1.ValueMember = "PermissionID"; }

    Read the article

  • Read specific line from text file, according to Checked Listbox selection number.

    - by Manolis
    Heya, i want to create an application which will read a specific line from a text file and show it in a textbox. The line will be chosen according to the number of the listbox selection i will make. Here's the code: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer For i = 0 To Me.CheckedListBox1.CheckedIndices.Count - 1 Me.CheckedListBox1.SetItemChecked(Me.CheckedListBox1.CheckedIndices(0),False) Next i End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If CheckedListBox1.CheckedItems.Count <> 0 Then Dim reader As New System.IO.StreamReader(CurDir() & "\" & "READ.txt") Dim x As Integer Dim s As String = "" For x = 0 To CheckedListBox1.CheckedItems.Count - 1 s = s & "Answer " & (x + 1).ToString & ") " & CheckedListBox1.CheckedItems(x).ToString & ControlChars.CrLf & reader.ReadLine() & ControlChars.CrLf & ControlChars.CrLf Next x Answer.Text = (s) Else MessageBox.Show("Please select questions.", "Error", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information) Return End If End Sub End Class So lets say i 'check' the first, second, and fifth items from the checked listbox, i want it to read from the text file the first, second, and fifth lines of text and show them in the textbox. The current code just reads line 1, 2, 3 (...) in order, no matter what item i have 'checked'. Thanks in advance!

    Read the article

  • Cross-thread operation not valid: accessed from a thread other than the thread it was created on.

    - by user307524
    Hi, I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:- Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on. i have tried invoke required but again got the same error. Sample code is below: private void button1_Click(object sender, EventArgs e) { // Create an instance of the test class. Class1 ad = new Class1(); // Create the delegate. AsyncMethodCaller1 caller = new AsyncMethodCaller1(ad.TestMethod1); //callback delegate IAsyncResult result = caller.BeginInvoke(checkedListBox1, new AsyncCallback(CallbackMethod)," "); } In class file code for TestMethod1 is : - private delegate void dlgInvoke(CheckedListBox c, Int32 str); private void Invoke(CheckedListBox c, Int32 str) { if (c.InvokeRequired) { c.Invoke(new dlgInvoke(Invoke), c, str); c.Items.RemoveAt(str); } else { c.Text = ""; } } // The method to be executed asynchronously. public string TestMethod1(CheckedListBox chklist) { for (int i = 0; i < 10; i++) { string chkValue = chklist.CheckedItems[i].ToString(); //do some other database operation based on checked items. Int32 index = chklist.FindString(chkValue); Invoke(chklist, index); } return ""; }

    Read the article

  • Dynamic checkboxlist

    - by Steve
    Hi, I am currently building a dynamic url tab system that user can say what urls they want to be displayed on a tabpage control. In the database i have the following columns. userID, int URLName var Enabled bit I am pulling the data back ok but what i am trying do is populate a checkbox list with the urlname and its status on a user options page so they can say what tabs they want displayed. I have wrote the following methods to get the urls and create the checkboxes however i keep getting the following error. ex = {"InvalidArgument=Value of '1' is not valid for 'index'.\r\nParameter name: index"} It reads the first row ok but when it hits the 2nd row that is being returned i get that error. Has anyone got any ideas? Thanks private void GetUserURLS() { db.initiateCommand("[Settings].[LoadAllUserURLS]", CommandType.StoredProcedure); sqlp = db.addParameter("@UserID", _UserID, SqlDbType.Int, ParameterDirection.Input); sqlp = db.addParameter("@spErrorID", DBNull.Value, SqlDbType.Int, ParameterDirection.InputOutput); db.executeCommand(); CreateCheckBoxes(db.getTable(0).Rows); db.releaseCommand(); } private void CreateCheckBoxes(DataRowCollection rows) { try { int i = 0; foreach (DataRow row in rows) { //Gets the url name and path when the status is enabled. The status of Enabled / Disabled is setup in the users option page string URLName = row["URLName"].ToString(); bool enabled = Convert.ToBoolean(row["Enabled"]); CheckedListBox CB = new CheckedListBox(); CB.Items.Insert(i, URLName); CB.Tag = "CB" + i.ToString(); checkedListBox1.Items.Add(CB); i++; } } catch (Exception ex) { //Log error Functionality func = new Functionality(); func.LogError(ex); //Error message the user will see string FriendlyError = "There has been populating checkboxes with the urls - A notification has been sent to development"; Classes.ShowMessageBox.MsgBox(FriendlyError, "There has been an Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }

    Read the article

  • C# How to place a comma after each word but the last in the list

    - by user576712
    I totally new to C# and learning as I go. I am stuck on issue which I'm hoping an experienced programmer can help. I have added a CheckedListBox to my form and added a collection of 6 items to it. I need all but the last item selected to have a comma placed beside it, so my question is: how can I tell C# NOT to place a comma beside the last item selected? foreach (object itemChecked in RolesCheckedListBox.CheckedItems) { sw.Write(itemChecked.ToString() + ","); } Thanks for any help received! Dan

    Read the article

1