D
Dean Bortell
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
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