I'll try to simplify the situations as much as possible.
I have an ActiveReports subreport that has a control which I fill using FetchData event. Sometimes I need to hide the control if its blank or in this occassion the value is Cotton but Polyester should appear. The problem is that when I hide a control, it hides the control on every occurrence in the report not just one instance that so need. Is there something I'm doing wrong.
I define the control in InitializeReport
Material1 = DirectCast(Detail.Controls("Material1"), Label)
Material2 = DirectCast(Detail.Controls("Material2"), Label)
I set up the Datafield for the control in the DataInitialize event
Fields.Add("Material1")
Fields.Add("Material2")
In the FetchData event, I fill the control, so three records, the control gets populated appropriately. There's nothing wrong. If the second record has a value then thats fine. e.g.
1st Record, first call of the FetchData event.
Fields("Material1").Value = "Polyester"
Material1.Value = "Polyester"
Fields("Material2").value = "Wool"
Material2.Value = "Wool"
2nd Record, second call of the FetchData event.
Fields("Material1").Value = "Cotton"
Material1.Value = "Cotton"
Fields("Material2").Value = "Wool"
Material2.Value = "Wool"
If I want to hide the second record/control from being seen, after the control is filled, I hide the control in the Details_Format event, however, it hides all three Material controls rather than just the one individual instance. What could I be doing wrong?
If Fields("Material1").value = "Cotton" then
Material1.Visible = false
End if
I want wool to appear twice, in both records but Cotton to not appear in the second grouping. I just can't hide the Cotton controls. I don't want to simply blank out the Material1 because I need to hide the control so that I can move controls up and reorganise the report. There is a label beside Material1 which I hide as well as the Material1.
VB or C# solution please.
You need to add Else to you If or replace with
Material1.Visible = Not (Fields("Material1").Value = "Cotton")
that way it turns on or off based on the value. When you set the property you're setting it on the instance for the whole control, the subreport has only one instance not one for each detail.
hope this helps.
Related
In ListView there are 3 option of SelectionMode
1.Single - only one item can be selected.
2.Multiple - you can select muliple items, one after the other.
3.Extended - You can select multiple items and used Ctrl or Shift key.
I'm need to select some items in ListView as text in TextBox.
i.e. press with the left button of mouse, until the mouse is up.
and mark all between items as Selected.
How can I make it?
Thanks
1.Single: SelectionMode="Single"?
2 Mutiple : i think use binding
enter link description here
3
enter link description here
Or You try this line SelectionMode="Muti..."
Firstly, the porpose of this problem is to display listView of TextBlocks for allow use ItemsSource of ListView for display text for several reasone.
behind each textBlock that contains a word, there are in the ViewModel class named Word. that contains the text of the word and property of IsSelected.
I solve this problem, by adding 3 EventSetter event to the ListViewItem,
1.PreviewMouseLeftDown
2.MouseEnter
3.PreviewMouseLeftUp
and adding a flag of IsInSelection, and two object Word that present the control in the view,1.firstSelectionWord, 2.lastSelectionWord.
and, when the first event raise, i update the current control to be Selected.
and set a flag IsInSelection to true. and set firstSelectionWord = lastSelectionWord = current word pressed.
in the MouseEnter event i checked if IsInSelection is true, and them mark also the current control to Selected=true. set the lastSelectionWord = current word pressed.
and call a method that mark all the Word between them as selected.
in the PreviewMouseLeftUp function, i set the IsInSelection = false.
I've used this control before and it was very straight forward. I have a data grid view which is bound to a data source. I add a binding navigator control to the form and set it to use the same binding source as the data grid view. I add a text box, which I use to filter the results that appear in the data grid view, and modify the navigator to remove the add and delete items, so all it contains is the navigation buttons an the text box. Everything appears fine until I select a row in the grid...while the row number in the navigator is correct, there is a big red "X" that spans the entire navigation bar, which spans the entire top of the form. I've included a snapshot here:
I get no warnings or exceptions, and have the debugger set to break on any exception thrown. I feel like I am missing something obvious, but it continues to "work", in that the filter works properly and the row number is always correct. Any advice for helping fix this would be greatly appreciated. The data grid view selection change does modify the contents of the form (other controls on the form) but that all works perfectly.
As far as example code, both the data grid view and the binding navigator use a sql view which was added as a data source.
this.dgvSerial.DataSource = this.vwSerialBindingSource;
this.bindingNavigator1.BindingSource = this.vwSerialBindingSource;
I then set the filter for the binding source to be on the text box that resides in the binding navigator:
vwSerialBindingSource.Filter = string.Format("ProductName LIKE '%{0}%' OR LabelProductName LIKE '%{0}%' OR SerialNumber LIKE '%{0}%'", tb.Text);
I do also add a "search button", with an image which is loaded as an embedded resource.
// setup the search button, the image is
// an embedded resource
bindingNavigator1.ImageList = new ImageList();
Assembly _assembly = Assembly.GetExecutingAssembly();
Stream _imageStream = _assembly.GetManifestResourceStream("SNReprint.search.png");
Image currentImage = Image.FromStream(_imageStream);
ToolStripButton searchButton = new ToolStripButton();
searchButton.Image = currentImage;
searchButton.Text = "Search";
searchButton.Font = new Font(searchButton.Font, FontStyle.Bold);
searchButton.BackColor = Color.Lavender;
// Add the button to the toolstrip
bindingNavigator1.Items.Add(searchButton);
There are a bunch of other controls on the form which are bound to columns in the view which are not affected.
I'm not sure what other code I should provide, so much of it is designer generated, and every other aspect of the application works perfectly. Since this problem doesn't appear until the data grid view selection changed event is raised, I have to assume that I'm doing something in this event handler to cause the binding navigator to render incorrectly.
IF there is anything else specific that I can provide that might shed some light on the problem I am more than happy to post it...
I am dynamically adding a textbox to certain rows (one column only) of a gridview. I add the controls with this insdie of a test condition (works fine):
TextBox txtASIN = new TextBox();
txtASIN.ID = "TxtASIN" + e.Row.RowIndex;
e.Row.Cells[4].Controls.Add(txtASIN);
int i = e.Row.Cells[4].Controls.Count; //TEST: This returns 1 correctly
I want the user to be able to enter values into one or more of these textboxes and then update the database with a single button click (not one click for each row). The problem I'm having is how to access those values on a button click event. I did a simple test this way to try to see the value in the second row but get null in temp1 (I am certain there is a value entered in that textbox):
protected void btnUpdate1_Click(object sender, EventArgs e)
{
TextBox temp = (TextBox)GridView2.Rows[1].FindControl("txt1");
string temp1 = temp.Text;
int i = GridView2.Row.Cells[4].Controls.Count; //TEST: This returns 0 incorrectly }
Once I can make this work, I can iterate through the rows and do what I need to do with the values. I don't know if the text entered in the textbox is actually readable without a postback but I'm otherwise stumped. Open to better suggestions on how to do this.
Thanks.
EDIT: Here is where I am now. I can see the textboxes in my column fine. I put a break in on a button that attempts to read them and this is what I'm seeing. If I check GridView2.Rows[0].Controls.Count, I get 8, which is the correect number of columns. If I check GridVeiw2.Rows[0].Cells[4].Controls.Count, I get 0, which is wrong because the textbox is there. I can get a Count of 1 right after I dynamically create it but not when I perform a subsequent button click.
Can anyone explain this? I feel if I can get past this holdup, I can get the rest done.
Thanks again.
You need to assign an ID to the TextBox controls and then access them by that ID in FindControl(). Also, make sure you're adding the controls in the Page's Init() method of the life-cycle. That way it gets added to ViewState.
TextBox txt1 = new TextBox();
txt1.ID = "txt1";
e.Row.Cells[4].Controls.Add(txt1);
EDIT: I just remembered another possible solution. Instead of programatically creating the TextBox controls in the code-behind just create a TemplateField in the GridView.
Add Textbox TemplateField Column To GridView Programmatically
I would try a different approach, putting the text box in the html markup of the page and then control the visible or readonly property of it on the ItemDataBound event. That way, the control will always be there and you don't have to worry about the lifecycle stuff.
I have a couple GridViews that are dynamically created and placed into a PlaceHolder. When I mouse over the Select button, it shows __doPostBack('ctl00$bodyPlaceHolder$ctl0X','Select$Y'), where X = what I think is the GridView/Control index for the page and Y = row number of that GridView.
Since it is dynamically creating the GridViews, it makes sense that names them ctl0X, but on the PostBack how do I use this information?
I wouldn't even have this problem if adding the SelectedIndexChanged EventHandler worked, but it never gets called.
I found one other question like this, but the answer involved adding a GridView within my GridViews, which would also have to be dynamic, which brings me back to the original problem.
Edit
Okay, so I set gridViewDynamic.ID = "blahblah" + r.LastName, thus giving each GridView a unique name, so on mouseover in the page I get __doPostBack('ctl00$bodyPlaceHolder$blahblahSmith',Select$Y, I still can't access the items on PostBack because they no longer exist. So, I added the same GridView creation code to an if(IsPostBack), then called GridView gView = (GridView)this.Page.FindControl(blahblahSmith). Great, gView isn't null. But all the data in the rows are. Calling gView.Rows[0] returns null.
Use Page.FindControl("TheNameYouGaveTheDynamicGridView")
GridView grid = Page.FindControl("TheNameYouGaveTheDynamicGridView") as GridView;
If you are using MasterPages, you need to take a different approach to find the control on the page, but it is the same premise.
How can I prevent bindingSource Current item from changing?
(there is no changing event with cancel argument...)
This is scenario:
I have a dataGridView, and text-boxes on the same form.
I am using text-boxes to change values in the datasource (with standard databinding)
Bindings are written manually (After save button is clicked)
When user selects another row using DataGridView, bindingSource.Current propery is changed, and text boxes are updated with values from selected row. Changes that user entered are lost.
Is there any way to prevent this problem?
Can I prevent bindingSource.Current property from changing?
Is there any better option to prevent this behaviour?
(disabling dataGridView is unfortinutelly not an option)
It sounds like you don't want to not change bindingSource.Current, but rather you want to save the contents of the text boxes before you change the current row? If you've bound a collection to the bindingSource, then don't the text boxes refer to properties in the current element in that collection?
I'm not really sure what you're trying to do, but a shot in the dark might be to bind the same DataSource to two different BindingSource objects, something like this:
gridBindingSource.DataSource = theDataSource;
textBoxBindingSource.DataSource = theDataSource;
myDataGrid.DataSource = gridBindingSource;
firstNameTextBox.Bindings.Add (new Binding ("Text", textBoxBindingSource, "FirstName"));
but this would be weird, because if theDataSource is appropriate for a grid control, then it's a collection of things that have a FirstName property. Maybe if you were more specific in your question.
ETA: If you want to save the text box contents to the current row, call ValidateChildren () on the container before the bindingSource.Current property changes.
I have a somewhat similar framework with both grid and textboxes on same form. When user clicks the EDIT button (or Add), I just disable the gridview control itself...
MyDataGrid.Enabled = false;
continue editing..
Then in the SAVE, if all is ok,
MyDataGrid.Enabled = true;