473,406 Members | 2,371 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,406 software developers and data experts.

checked list box

I fill a checked listbox with name from dataset.

I would like to go through that names and if I find the same name in list,
then that line should be checked.

How?

Hrcko
Nov 17 '05 #1
3 5963
Hi Hrvoje,

I feel something is missing from your question.

In any case, the ListBox will be filled with DataRowViews, so simply go through all DataRowViews in the ListBox.Items collection and if the row qualifies, check the appropriate ListBox item

for(int i = 0; i < listBox1.Items.Count; i++)
{
DataRowView d = (DataRowView)listBox1.Items[i];
if(d["Column1"].ToString() == "SomeValue")
listBox1.SetItemChecked(i, true);
}

Note that you cannot do this in the constructor in the parent control (form) as SetItemChecked will be ignored. You can however do it in the Form's Load event.

On Thu, 19 May 2005 13:09:40 +0200, Hrvoje Voda <hr*********@luatech.com> wrote:
I fill a checked listbox with name from dataset.

I would like to go through that names and if I find the same name in list,
then that line should be checked.

How?

Hrcko


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2
It doesn't work.

I get an error on DataRowView line : Specified cast is not valid.

Maybe I should put it somewhere in listBox control properties...
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op.sq0t67o1klbvpo@stone...
Hi Hrvoje,

I feel something is missing from your question.

In any case, the ListBox will be filled with DataRowViews, so simply go
through all DataRowViews in the ListBox.Items collection and if the row
qualifies, check the appropriate ListBox item

for(int i = 0; i < listBox1.Items.Count; i++)
{
DataRowView d = (DataRowView)listBox1.Items[i];
if(d["Column1"].ToString() == "SomeValue")
listBox1.SetItemChecked(i, true);
}

Note that you cannot do this in the constructor in the parent control
(form) as SetItemChecked will be ignored. You can however do it in the
Form's Load event.

On Thu, 19 May 2005 13:09:40 +0200, Hrvoje Voda <hr*********@luatech.com>
wrote:
I fill a checked listbox with name from dataset.

I would like to go through that names and if I find the same name in
list,
then that line should be checked.

How?

Hrcko


--
Happy coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #3
Hm, you said you used a DataSet(DataTable) as DataSource? If so, there should be DataRowViews in the ListBox. In any case, you can check the type using Breakpoints or MessageBox.Show(listBox1.Items[0].GetType().ToString())
On Thu, 19 May 2005 15:06:42 +0200, Hrvoje Voda <hr*********@luatech.com> wrote:
It doesn't work.

I get an error on DataRowView line : Specified cast is not valid.

Maybe I should put it somewhere in listBox control properties...
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:op.sq0t67o1klbvpo@stone...
Hi Hrvoje,

I feel something is missing from your question.

In any case, the ListBox will be filled with DataRowViews, so simply go
through all DataRowViews in the ListBox.Items collection and if the row
qualifies, check the appropriate ListBox item

for(int i = 0; i < listBox1.Items.Count; i++)
{
DataRowView d = (DataRowView)listBox1.Items[i];
if(d["Column1"].ToString() == "SomeValue")
listBox1.SetItemChecked(i, true);
}

Note that you cannot do this in the constructor in the parent control
(form) as SetItemChecked will be ignored. You can however do it in the
Form's Load event.

On Thu, 19 May 2005 13:09:40 +0200, Hrvoje Voda <hr*********@luatech.com>
wrote:
I fill a checked listbox with name from dataset.

I would like to go through that names and if I find the same name in
list,
then that line should be checked.

How?

Hrcko


--
Happy coding!
Morten Wennevik [C# MVP]



--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carlos Magalhaes | last post by:
Hi all, I am doing some work with a checked list box on a windows form. I bind a dataset to the checked list box and am setting a display member and a value member. I can loop through the...
26
by: Simon Jefferies | last post by:
Hello, I am trying to add an item to a checked list box, like: clbList.Items.add("Hello",true) I get an error back: Run-time exception thrown: System.ArgumentOutOfRangeException -...
1
by: Dennis | last post by:
I have a checked list box and am trying to use the SetItemCheck method as follows: mylistbox.SetItemChecked(indextoset, True) It seems to have no effect and the display does not show the box...
1
by: Jack | last post by:
Hello, I have a treeview with checkboxes and I want to get the Text of each checked item into an arraylist or something. Thanks, Jack
10
by: dm1608 | last post by:
Hi, all. I have a requirement for one of my programs to have a "Checked Listbox" that contains a list of all my local/remote drives. I woudl like users to click one or more drives that I need...
2
by: Aaron Reimann | last post by:
I have a lot of check boxes. This is an update of the check boxes, I want something was checked, then to do an insert (which is currently working), if something is no longer checked...delete the...
1
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
2
by: clintonG | last post by:
When selected="true" is declared in the CheckBoxList ListItem FireFox does not display checked list items. Even more curious is the absence of the checked="checked" attribute in the source which is...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
by: Soulless | last post by:
Hi, I have reason to need to use a checked list box. The list box contents will be filled with filenames in a directory. These values will change. I need the ability to be able to select a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.