Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey can any body tell me that i am searching a record and showing them in textbox. Some textboxes Are filled but some not because their is no data avilable in the datbase to those column. My problem is that i want to disable the textboxes which has data and keep enable those textboxes which have no date for further update.
pls help thanks in advance
Posted
Comments
Manfred Rudolf Bihy 3-Feb-11 10:06am    
Hey you're searching a record and then show them in textbox!
I told you that because you asked for it. :)

Doesn't textbox.Enabled = false do it? Am I missing something here?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Feb-11 1:18am    
Sorry, Indivara, you do miss the point. See my answer. (I don't vote)
--SA
Indivara 4-Feb-11 1:46am    
I still don't get it, Sergey... he wants to disable the textbox if the corresponding column in the database has no data, so,
if (column[index].data == empty) { textbox.Enabled = false; } else ...

(the if statement is pseudo-code, since there is no information about that)
Sergey Alexandrovich Kryukov 4-Feb-11 4:08am    
But I think I understand better now: data is presented in text boxes somehow, on some events we are not informed about; when data becomes non-empty, the text box is "opened for update" by the UI user (maybe to give a write the modification back to database). Two sources of causality: the user and something else. Why OP wants all that is a dark story; who knows them?..
--SA
C#
textBox.Enable = (string.IsNullOrEmpty(textBox.Text));
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Feb-11 1:21am    
John, excuse me: there is a typo in property name; and one pair of brackets is redundant, and you say nothing about triggering of this check/assignment (I do, not sure OP needs this though -- see my note about a trap in my answer).
--SA
The other answers are not enough. You should trigger the check of the content somehow. The only way to do it is handling the event

C#
myTextBox.TextChanged += delegate(object sender, EventArgs e) {
    TextBox textBox = (TextBox)sender;
    textBox.Enabled = string.IsNullOrEmpty(textBox.Text);
};


Now, let me tell you: this is a trap. As soon as you delete the text, your text box cannot be edited anymore. Are you not afraid :-)?

I'm not sure you want to trigger this stuff in this way, at least I gave you the idea. After all, you can re-enable the text box using some other control with textBox.Enabled = true. I hope (as much as I can see from your Question), some updates are coming from the database; in this case getting non-empty data can re-enable the text box as you need.

—SA
 
Share this answer
 
v4
Hi vijaysiwan17,:rose:
:thumbsdown:


Hi you check the Condition for whenever data is empty, then set the "Enabled=false"..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900