Avatar of Thomasian
Thomasian
Flag for Philippines asked on

Cancel Selection change of Listview control

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?
.NET ProgrammingEditors IDEsVisual Basic.NET

Avatar of undefined
Last Comment
Jorge Paulino

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
rachitkohli

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Thomasian

ASKER
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.
SOLUTION
Jorge Paulino

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Thomasian

ASKER
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 Paulino

>> 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!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Thomasian

ASKER
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 Paulino

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.
Thomasian

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jorge Paulino

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