By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,821 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

Listview checkboxes

P: n/a
I have a field in an access database that indicates if a
message is new. I have created a listview in vs .net
2003 and set checkboxes to true. when i try to check
each row in a datset and set individual listview items
state to checked/unchecked i get an error that says index
out of bounds. what is going on? here is the bad part
of my code:
private void bindList()
{
try
{

if (oleDbConnection1.State.Equals
(System.Data.ConnectionState.Closed))
oleDbConnection1.Open();
callInfoDS1.Clear();
callInfoDA.Fill(callInfoDS1.Tables["callInfo"]);
messageList.Items.Clear();
string[] s = new string[6];
int i = 0;
foreach (DataRow r in callInfoDS1.Tables["callInfo"].Rows)
{
s[0] = r["callDate"].ToString();
if (r["callRemarks"].ToString() != "")
s[1] = r["callRemarks"].ToString();
if (r["callFor"].ToString() != "")
s[2] = r["callFor"].ToString();
s[3] = r["callStart"].ToString();
s[4] = r["callInterval"].ToString();
s[5] = r["callNumber"].ToString();
ListViewItem l = new ListViewItem(s);
messageList.Items.Add(l);
int x = messageList.Items.Count-1;
if (r["callNew"].Equals(true))
messageList.Items[x].Checked=true;
i++;
}
}
catch (Exception bList)
{
MessageBox.Show(bList.Message);
}
}//end function
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi!

The "messageList.Items.Add" method shall return you a reference to the
ListViewItem object for the ListViewItem just added. Use the Index property
of the returned reference to get the "Correct" zero-based index to make it
checked. Or simply use the "Checked" property of the returned reference to
make it checked.

Regards,
Kumar Gaurav Khanna

--
----------------------------------------------------------------------------
----------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
OpSupport - Spelunking Rotor
http://opsupport.sscli.net/
----------------------------------------------------------------------------
----------

"Dean Bortell" <bo*****@sbcglobal.net> wrote in message
news:04****************************@phx.gbl...
I have a field in an access database that indicates if a
message is new. I have created a listview in vs .net
2003 and set checkboxes to true. when i try to check
each row in a datset and set individual listview items
state to checked/unchecked i get an error that says index
out of bounds. what is going on? here is the bad part
of my code:
private void bindList()
{
try
{

if (oleDbConnection1.State.Equals
(System.Data.ConnectionState.Closed))
oleDbConnection1.Open();
callInfoDS1.Clear();
callInfoDA.Fill(callInfoDS1.Tables["callInfo"]);
messageList.Items.Clear();
string[] s = new string[6];
int i = 0;
foreach (DataRow r in callInfoDS1.Tables["callInfo"].Rows)
{
s[0] = r["callDate"].ToString();
if (r["callRemarks"].ToString() != "")
s[1] = r["callRemarks"].ToString();
if (r["callFor"].ToString() != "")
s[2] = r["callFor"].ToString();
s[3] = r["callStart"].ToString();
s[4] = r["callInterval"].ToString();
s[5] = r["callNumber"].ToString();
ListViewItem l = new ListViewItem(s);
messageList.Items.Add(l);
int x = messageList.Items.Count-1;
if (r["callNew"].Equals(true))
messageList.Items[x].Checked=true;
i++;
}
}
catch (Exception bList)
{
MessageBox.Show(bList.Message);
}
}//end function

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.