Question for the experienced

  • Thread starter Thread starter h
  • Start date Start date
H

h

....or at least it seems like it is, to me.

I have built this custom list control which has list items which are
also custom made controls that consist of textboxes, labels and
buttons.

Structure goes:

Custom List control
|__ Custom List item control (for list rows)
|__ Textboxes, Labels, Buttons...

I want to click on a list item and have it selected. I did that using:

public void AddListItem()
{
...
li.Click += new EventHandler(li_Click);
pnlList.Controls.Add(li);
...
}

private void li_Click(object sender, EventArgs e)
{
if (m_liSelected != null)
m_liSelected.BackgroundEx =
Color.LightPink;

m_liSelected = (ListItemControl)sender;
m_liSelected.BackgroundEx = Color.IndianRed ;

ListItemSelectedEventArgs args = new
ListItemSelectedEventArgs((string)m_liSelected.Amount);
if (ListItemSelected != null)
ListItemSelected (this, args);
} etc.


However, what I WANT TO ADD to this functionality is that when I click
on a text box placed on the List Item, that the row gets selected (as
if I clicked on a ListItem control itself.

So, in case I didn't make myself clear, clicking on a user control
works, but I have no idea how to "transfer" that behavior to controls
on the user control.

Anyone, please help, I'm hitting the wall here.

thanks,
h
 
h,

I would have your parent control (the list view) attach event handlers
to the GotFocus event for every control in the row. Then, in your list
view, when the event is fired, get the parent of the control that has the
focus, and when you get to the row control, determine which row should be
highlighted.

Hope this helps.
 
You can try this,

1. First get the client co-ordinate of your cursor.

example:
Point p = lstbox1.PointToClient(new Point (Cursor.Position.X
,Cursor.Position.Y));

2. Get the rectangle using the function listbox1.GetItemRectangle(index)

3.Loop it out and find out which item belongs to your cursor points

4. Select that item

Shak.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top