I have a listview with a number of drawn checkboxs in it.
Currently when I click the drawn checkbox on the listview it either clicks the first check box in that column or nothing at all.
I have know it has something to do with the temppoint, so after I post this hopefully I can come to the solution myself before someone answers :P.
This is where the checkbox is drawn
private void lstSourceToUser_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex > 1)
{
int usrIndex = userProfile.GetUserIndexByID(e.Header.Name);
int srcIndex = userProfile.GetUsersSourceIndex(e.Header.Name, e.Item.SubItems[0].Text);
Graphics g = e.Graphics;
CheckBoxRenderer.DrawCheckBox(g,new Point((e.Bounds.X + e.Bounds.Width/2 -10 ),(e.Bounds.Y)), userProfile.SystemUserList[usrIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
}
else
// Draw the other subitems with default drawing.
e.DrawDefault = true;
}
And this is where the click event happens
private void lstSourceToUser_MouseClick(object sender, MouseEventArgs e)
{
ListViewItem.ListViewSubItem subItem = lstSourceToUser.HitTest(e.X, e.Y).SubItem;
if (subItem.Name != "")
{
Point tempPoint = new Point(e.X, e.Y);
int userIndex = userProfile.GetUserIndexByName(subItem.Name);
Rectangle rect = new Rectangle(subItem.Bounds.X, subItem.Bounds.Y, 100, subItem.Bounds.Height);
if (rect.Contains(tempPoint))
{
int srcIndex = userProfile.GetUserSourceIndexByUserName(subItem.Name, lstSourceToUser.SelectedItems[0].SubItems[0].Text);
userProfile.SystemUserList[userIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState = !userProfile.SystemUserList[userIndex].fusionUserSources[srcIndex].UserSourceChkBox.MyCheckedState;
this.lstSourceToUser.Invalidate();
}
}
}
Any help would be appreciated be it solutions or links/guides :) Thank you
Aucun commentaire:
Enregistrer un commentaire