473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Validating Combo boxes in WinForms

Hello:

Using WinForms, certain users may change the value in a combobox,
others may not.

Some of these boxes open with a default value.

I need to check the user's rights before committing his or her
changes in the box and restore the previous value if he or she is not
allowed (or not let the value be changed in the first place).

I can get the permissions and check them OK, but I don't know how to
manage the combobox. I'm not sure which events I should use.
SelectedIndexChanged isn't much help because it fires off when the
form opens because the value is being set programatically.

Any help would be much appreciated. Thanks.

Ken

Nov 17 '05 #1
2 4900
On Thu, 21 Jul 2005 23:26:51 -0400, Ken Loomis
<no*************@nodomain.com> wrote:

Using WinForms, certain users may change the value in a combobox,
others may not.

Some of these boxes open with a default value.

I need to check the user's rights before committing his or her
changes in the box and restore the previous value if he or she is not
allowed (or not let the value be changed in the first place).

I can get the permissions and check them OK, but I don't know how to
manage the combobox. I'm not sure which events I should use.
SelectedIndexChanged isn't much help because it fires off when the
form opens because the value is being set programatically.


OK. I found "Validating." It works well. Now the only thing I need
to be able to do is reset the original value and allow the user to
continue. Right now it's stuck on the error.

Can I get the value somewhere and resent it?? Then I suppose I change
the e.Cancel to false??

My code:

private void cmbStatus_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
bool blnOk = false;
foreach (DataRow permissionsDataRow in tblPermissions.Rows)
{
int theRole =
Convert.ToInt32(permissionsDataRow["RoleID"]);
if (theRole == (int)frmMain.Role.Manager )
{
blnOk = true;
}
}
if (blnOk == false)
{
e.Cancel = true;
this.errorProvider1.SetError(cmbStatus, "You do not
have permissions to change this field.");
}
}


Nov 17 '05 #2
On Thu, 21 Jul 2005 23:26:51 -0400, Ken Loomis
<no*************@nodomain.com> wrote:

Using WinForms, certain users may change the value in a combobox,
others may not.

Some of these boxes open with a default value.

I need to check the user's rights before committing his or her
changes in the box and restore the previous value if he or she is not
allowed (or not let the value be changed in the first place).

I can get the permissions and check them OK, but I don't know how to
manage the combobox. I'm not sure which events I should use.
SelectedIndexChanged isn't much help because it fires off when the
form opens because the value is being set programatically.


OK. I found "Validating." It works well. Now the only thing I need
to be able to do is reset the original value and allow the user to
continue. Right now it's stuck on the error.

Can I get the value somewhere and resent it?? Then I suppose I change
the e.Cancel to false??

My code:

private void cmbStatus_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
bool blnOk = false;
foreach (DataRow permissionsDataRow in tblPermissions.Rows)
{
int theRole =
Convert.ToInt32(permissionsDataRow["RoleID"]);
if (theRole == (int)frmMain.Role.Manager )
{
blnOk = true;
}
}
if (blnOk == false)
{
e.Cancel = true;
this.errorProvider1.SetError(cmbStatus, "You do not
have permissions to change this field.");
}
}


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel Hill | last post by:
OK, I have very, VERY basic background knowledge of VB6 and have now upgraded to VB.NET and now I'm struggling to bring up the forms I want. What I am looking to do is to have a click a command...
0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
0
by: Ken Loomis | last post by:
Hello: Using WinForms, certain users may change the value in a combobox, others may not. Some of these boxes open with a default value. I need to check the user's rights before committing...
1
by: Brendan | last post by:
I am trying to validate the data in all of the text and combo boxes. The text box validation seems to be working fine, but I am having the hardest time with the combo box validation. I am not sure...
0
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
4
by: User | last post by:
Hi people, Excuse if my question is silly, but... i have 2 combo boxes in my project they are binded to fields from same table... one is binded do Code field and another to Description field...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.