We help IT Professionals succeed at work.

Cancel Selection change of Listview control

932 Views
Last Modified: 2013-11-26
I have a list view control which shows all the employee names. The user can select the employee to be edited by clicking an item in the listview control. The info of the employee will be displayed in a group of textboxes where the user can make the necessary changes.

The input will only be validated when the user selected another employee or the save button is clicked. If there is an invalid input, the corresponding control will have focus.
e.g., if the user leaves the name blank, a message will be displayed then the textbox control for the name will have focus.

How do I stop the listview from changing the selecteditem if an invalid input is found?
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
rachitkohli,

Thanks for the suggestion. I have thought about that but I think that it is a troublesome for the user to have to click a Save button after editing each employee.
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
jpaulino,

I chose to use a listview because I don't intend to show every property of the employee
e.g. password - although only * will be shown

I have never used a datagridview. Is it more suitable for what I'm trying to do?
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
>> I have never used a datagridview. Is it more suitable for what I'm trying to do?

Datagridview is the "perfect" control to edit data. You can hide some columns if you don't want to show to the user, lock others, etc.

I think you should have a look on that!

Author

Commented:
If I hid the columns, how can the user edit the data? I want the user to be able to edit all info but don't want to tabulate all of them in the list (it's kinda weird to show a column of password full of *'s). And some of the data are quite long do be shown in a table (e.g. address), some can be selected from a list (e.g. department), some will be datetime values (e.g. schedule), etc..

I will use a listview only for displaying a list of the employees, and the selected item can be edited by several controls (textboxes, comboboxex, etc..). I know that using datagrid is much faster for inputing large number of records, but that won't be an issue in my case ('employees' is just an example). I just need it to be user-friendly. I don't need it to be fast for inputing data since there won't be a large number of records and it's rarely modified. I just need it to be easy to use, even for beginners (maybe add some tooltip) and as much as possible limit the chances of errors in user input (e.g. datetimepicker to input schedule).
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
You can do the same using a datagridview. When you populate the dgv you just have to select (using the select statement) the fields you like to show, like "SELECT field1, field2, field5 FROM myTable"

You can also hide or lock some column you want.

It's a very powerfull control that you should use more offen.

Author

Commented:
I will take a look at the dgv but I have a few concerns:
1. Should the data source be a query (database)?
2. If so, does it automatically save the changes to the database?
3. How do you handle long texts (address)? Do I have to scroll through the box to see the whole text?
4. Can I limit the user input (not data validation)? e.g. user can choose from a list/ a check box for yes/no fields

Anyway, you don't need to answer those here. I will post another question when I learned more about the control. But for now, I think the listview should be enough. Is there a way to do what I want? If not, any workaround?
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
1 - You use bound the datagridview using a select statement OR not. I'ts you choise.
2 - If it's bound to the any datasource it could automatically save the changes to the database
3 - Yes, if you show the text there. You could do the same as listview only for the long texts.
4 - You can use on the datagridview columns, checkbox's, combobox's or create your own types
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.