Link to home
Start Free TrialLog in
Avatar of conrad2010
conrad2010

asked on

populate checkbox in listview - Winforms (VB or C#):

Winforms
VS2008

If I set theproperty  "CheckBoxes=true" in a ListView, the first column will show a checkbox.

How can I populate this checkbox when looping through a dataset?

I have something like this for a regular checkbox:
this.chkActive.Checked = (rdr["active"].ToString() == "1") ? true : false

how can I do the same for the checkbox in a ListView?

ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of conrad2010
conrad2010

ASKER

The 2 error messages are:

"Error 10 The best overloaded method match for 'Gizmox.WebGUI.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid arguments"

and

Error 11 Argument '1': cannot convert from 'bool' to 'string'

This code sample fills a ListView, first column is the checkbox (and the field isActive is a BIT)...

while (rdr.Read())
                {
                    ListViewItem lItem = ListView1.Items.Add((rdr["isActvie"].ToString() == "1") ? true : false);
                    lItem.SubItems.Add(rdr["transactionID"].ToString());
                    lItem.SubItems.Add(rdr["datecreated"].ToString());
                    lItem.SubItems.Add(rdr["documentType"].ToString());
                    lItem.SubItems.Add(rdr["documentID"].ToString());
                }