Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I have created a form using Data Repeater and have inserted some labels and textboxes. Firstly, I deserialized XML file into an object and bind it to the data repeater. I have also binded the labels and textboxes with the appropriate datatable columns. Here are my following codes:

These are the labels and textboxes binded to the data I want to display:

C#
TagLabel.DataBindings.Add("Text", ds, "Tag");
PrecedenceLabel.DataBindings.Add("Text", ds, "Precedence"); 
DataTypeLabel.DataBindings.Add("Text", ds, "DataType");           
LengthLabel.DataBindings.Add("Text", ds, "Length");           
ValueTextBox.DataBindings.Add("Text", ds, "Value");           
MaxTextBox.DataBindings.Add("Text", ds, "Maximum");           
MinTextBox.DataBindings.Add("Text", ds, "Minimum");           
OverflowTextBox.DataBindings.Add("Text", ds,"OverflowBehaviour");
    
bindingsource.DataSource = ds;
dataRepeater.DataSource = bindingsource;
dataRepeater.DataMember = "Preference";


After this, I want to hide some ValueTextbox if it's DataTypeLebel is "Autoinrement" with the following codes:


C#
for (int i = 0; i < dataRepeater.ItemCount; i++)
            
{                
//Update the CurrentItemIndex                
dataRepeater.CurrentItemIndex = i;
                
 if (((Label)dataRepeater.CurrentItem.Controls["DataTypeLabel"]).Text == "AutoIncrement")                
 {
                    
 ((TextBox)dataRepeater.CurrentItem.Controls["ValueTextBox"]).Visible = false;           
 }                
            
}


When the form is loaded, the row 5 ValueTextBox is hidden, which is correct. However, as I scroll down the form, some other ValueTextBoxes are also hidden, whhich are not correct. After a while the ValueTextBoxes are hidden on other rows and basically they are not maintained. Can anyone suggest what have I missed?
Posted
Comments
n.podbielski 4-Oct-12 7:40am    
Did you test if this ValueTextBoxes, that are hidden incorectly, are hidden on server or on JS?
YHiew 4-Oct-12 8:33am    
I am not using server or JS. This is a windows form application. I don't have database, just deserialized from XML.
n.podbielski 4-Oct-12 8:43am    
Oh yeah I missed that. But still. Did you try to breakpoint code hiding those controls?
YHiew 4-Oct-12 8:45am    
Yes I did. I did a console print out where the condition is met and the textbox is made invisible. The print out only happened once which is correct. However, as I scroll the form, some other textboxes appear invisible and randomly. Basically the control property is not maintained in the data repeater
n.podbielski 4-Oct-12 8:58am    
I would bind visible property to some property of the model. I think the problem is current item of repeater. Was not it suppose to change when you scroll?

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



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