G
Gav
Hi all,
I got some sample code from the following website:
http://msdn.microsoft.com/library/d...systemwindowsformslistboxclasssortedtopic.asp
This example is actually showing how to invert the selection on a listbox so
this is my code:
myda = new SqlDataAdapter(mycom);
dsRet = new DataSet();
try
{
conSQL.Open();
myda.Fill(dsRet, "BRANCHES");
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
conSQL.Close();
}
lbBranch.ValueMember = "BRANCHID";
lbBranch.DisplayMember = "BRANCHNAME";
if (dsRet.Tables["BRANCHES"]!= null &&
dsRet.Tables["BRANCHES"].Rows.Count>0)
{
lbBranch.DataSource = dsRet.Tables["BRANCHES"].DefaultView;
for (int nCounter = 0;nCounter < lbBranch.Items.Count;nCounter++)
{
if (lbBranch.GetSelected(nCounter)== false)
lbBranch.SetSelected(nCounter, true);
}
}
For some reason this is not working I have stepped through the code and it
seems to be executing correctly (ie it skips the first item because it is
already selected and executes the statement for the rest of the items),
however it does not seem to be selecting the items in the listbox. Does
anybody have any ideas where I could be going wrong?
Thanks
Gav
I got some sample code from the following website:
http://msdn.microsoft.com/library/d...systemwindowsformslistboxclasssortedtopic.asp
This example is actually showing how to invert the selection on a listbox so
this is my code:
myda = new SqlDataAdapter(mycom);
dsRet = new DataSet();
try
{
conSQL.Open();
myda.Fill(dsRet, "BRANCHES");
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
conSQL.Close();
}
lbBranch.ValueMember = "BRANCHID";
lbBranch.DisplayMember = "BRANCHNAME";
if (dsRet.Tables["BRANCHES"]!= null &&
dsRet.Tables["BRANCHES"].Rows.Count>0)
{
lbBranch.DataSource = dsRet.Tables["BRANCHES"].DefaultView;
for (int nCounter = 0;nCounter < lbBranch.Items.Count;nCounter++)
{
if (lbBranch.GetSelected(nCounter)== false)
lbBranch.SetSelected(nCounter, true);
}
}
For some reason this is not working I have stepped through the code and it
seems to be executing correctly (ie it skips the first item because it is
already selected and executes the statement for the rest of the items),
however it does not seem to be selecting the items in the listbox. Does
anybody have any ideas where I could be going wrong?
Thanks
Gav