473,385 Members | 1,863 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,385 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 4899
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.