473,378 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

VB.NET App: CheckedListBox item not showing up as "Checked"

language: vb.net
environment: windows forms
.net : v1.1

i am having a checkedlistbox control that display document category such as text, image, video, audio etc. these values are coming from database. when a user clicks any of the above values and saves the form, the item's "value" is getting saved in database. and when a user logs back in, his/her previously checked value items should be shown as checked.

Everything is working fine except a checked item is not showing up as checked in the form when i try to do it programmitacally. i know that the code is actually setting the item's checked property to true because itemCheck event gets fired immediately after my code but it just cant show it as checked in the form. here is my vb.net code

Expand|Select|Wrap|Line Numbers
  1. sub showCategory()
  2.     dim dt as new datatable
  3.     dt=getDocumentCategory() ' returns doc category as datatable
  4.  
  5.     Dim catarr As New ArrayList
  6.     catarr = getCheckedCategory(userid) 'array of previously checked items
  7.     catarr.TrimToSize()
  8.  
  9.     Me.SuspendLayout()
  10.     clbCategory.DataSource = dt.DefaultView
  11.     clbCategory.DisplayMember = "category_name"
  12.     clbCategory.ValueMember = "id"
  13.     If companyid > 0 Then
  14.            For i As Integer = 0 To clbCategory.Items.Count - 1
  15.                Dim row As DataRowView = clbCategory.Items.Item(i)
  16.                If catarr.IndexOf(row(0)) >= 0 Then
  17.                         clbCategory.SetItemChecked(i, True) '<-- this line is setting the item's checked property to true and itemCheck event is getting fired as it should but windows form is not showing up this item as checked.
  18.                         clbCategory.SetSelected(i, True)
  19.                End If
  20.            Next
  21.     End If
  22.     Me.ResumeLayout()
  23. end sub
  24.  
do you have any idea as to why form is not showing up checkedlistbox's item as "checked" in the final output??
Dec 3 '07 #1
6 4158
kenobewan
4,871 Expert 4TB
Possibly due to postbacks. HTH.
Dec 3 '07 #2
CyberSoftHari
487 Expert 256MB
You have to post code of this (clbCategory.SetItemChecked(i, True) ) method. we cannot identify what you done in this method!
Suggestion: Do not call a method inside “for” loop just for check an item.
Dec 3 '07 #3
Possibly due to postbacks. HTH.
there is no postback. i am calling this function on form load.
Dec 3 '07 #4
You have to post code of this (clbCategory.SetItemChecked(i, True) ) method. we cannot identify what you done in this method!
Suggestion: Do not call a method inside “for” loop just for check an item.
SetItemChecked function is not written by me. its there in checkedlistbox class :)
Dec 3 '07 #5
CyberSoftHari
487 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. If catarr.IndexOf(row(0)) >= 0 Then 
is this validation is true?
Dec 3 '07 #6
never mind.......problem solved :)
i put the whole code in form_paint event instead of form_load and its WORKING but cant tell u why. what do u think??

thanx for the responses anyway!
Dec 4 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John E | last post by:
How do I get whether a checkbox is ticked in a form on a form's submission (true or false)? How do I use the Request object in ASP?
4
by: Brett | last post by:
Why would you not want to use checked on any type of mathematical operation? Or use unchecked for that matter? Thanks, Brett
0
by: bredal Jensen | last post by:
Dear gurus, I have a "farm " of radio buttons server control in a table. I need to detect when the user has selected any of them( before any postback). i'm not quit sure how to do this. Is...
4
by: Jim Bancroft | last post by:
Hi everyone, I'm using a DataGrid with TemplateColumns. My DataGrid is located in a cell of an asp:Table. I did this so it's positioned correctly onscreen. One of the DataGrid's...
0
by: SGibson | last post by:
How would I display a partially checked node? What I mean by this is, rather than a completely checked or unchecked node, a node that displays a grey check mark when some of its children are...
0
by: Jon | last post by:
If anyone can help...Whenevr I go into a form and use the ctrl+F to find something with the binoculars the "Search field as formatted" is checked as default. This seems to slow down the find...
12
by: ssh | last post by:
function testfn(name) var tbody = document.getElementById('hellospace').getElementsByTagName('tbody'); var row = document.createElement('TR'); var cell1 = document.createElement('TD');...
1
by: jamesicus | last post by:
.......... just for curiosity? "real" XHTML served as content (MIME) type application/xhtml+xml will display in MSIE 6.0 release 2900 and 7.0 but they will not render xml content. However, MSIE...
1
by: AliRezaGoogle | last post by:
Dear Members Hi, I have a question: Why doesn't "checked" work for sub calls? For example consider the following snippet of code: checked { Overflower(); }
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.