How to implement TreeMaps DrillDown on Button Click? - c#

I am using the treemaps for an application development. The problem I am facing is that I want to use a button to remove the level I have traversed. I have tried but there is no use. I am new to WPF programming and I am not sure about all the methods that can be used. I have put a button and I have been able to retrieve the level number and reduce the level number onClick. but the level is the same. I used drilldown property for the tree maps. But I am not sure of implementing it by use of a button. Sample is mostly preferred as a beginner. Hope for a reply sooner.
Scenario:-
I was using a squarified treemap for visualising a data that consisted of 4 levels. I drillDown the map to view certain details. For example, I have a world map that shows the continents separately. I have clicked on any of the continent, say Asia, I will get another level that shows the countries as a treemap level and further clicking on the country leads me to the cities or states. Like wise I can move backwards without an problem. Now, I am using a button to remove the levels I am currently located in. I am not able to do so and could you please help me with a code snippet for the button

I am partially there, but a detailed research will help me. It took a long time for me to settle in this.
private void Back_Click(object sender, RoutedEventArgs e)
{
int level = TreeMap.Levels.Count;
if (level >= 1)
{
TreeMap.Levels.RemoveAt(level-1);
}
}
This code can only be used to change the level, not the visual of the same level. It will not get you back to the desired screen, but you can notice the level change once you debug and use Watch.

Related

How to select multiple elements in a Revit drawing

I'm trying to create a "Multi-Select" method in Revit (for 2016/2017) where the users can select specific parameters of instances contained within a drawing (like Nominal Diameter, Pipe Type and so on), and it will select all the instances within the drawing based on their selections. First, screen shot:
Let's predicate this with the fact that this window is created dynamically based on contents of the drawing. Nothing gets put in this window unless there is an element in the drawing that contains/meets one or more of these parameters.
So, ideally, when I Click the DO IT! button, I would like it to select all of the elements in the drawing that have meet any of these parameters. I can filter through this window and find all of my selections - now I just don't know what do with the selections.
I've looked through the Revit.chm and source and found the Selection namespace and class. There are functions like:
PickObject(ObjectType objectType);
that seem like they would be what I want, but I don't know if it's REALLY what I need. Furthermore, if that IS, in fact, what I'm looking for, I don't know the syntax of how to use it.
A little code:
I have a method that collects all of the users' selections:
private List<CheckBox> GetUserFilterPrefs()
{
//CYCLES THROUGH ALL THE PANELS AND BOXES IN THE WINDOW
return lstCheckBox;
}
Now I want to create my EventHandler for btnDoIt_Click...
I started it, but I'm walking in the dark on this part.
private void btnDoIt_Click(object sender, RoutedEventArgs e)
{
int itr = 0;
GetUserFilterPrefs();
List<Reference> lstRefs = new List<Reference>();
foreach (CheckBox cb in lstCheckBox)
{
if (lstElts[itr].Name == cb.Name)
{
//HOW DO I SELECT ALL ITEMS LIKE THE GIVEN ELEMENT
//THAT ARE RELATED TO THE CHECKBOX SELECTION??
}
itr +=1;
}
I'll obviously keep looking around; but if anyone knows a way, or can point me in the right direction, it would be massively helpful!
THANKS!!!
The PickObject function that you've found is one that asks the user to select an object in the model. Based on your description, that is not what you are looking for.
The function you need is:
SetElementIds(ICollection<ElementId> elementIds)
It is also part of the Selection class. This will highlight the desired elements in the model. To clear the selection in the model, pass an empty List as your argument. Passing null will cause an exception to be thrown.
To focus on the elements, you need the function:
UIDocument.ShowElements
There are a number of overloads for this function. Note that none if the elements are in the currently open view, Revit will attempt to find the best view for you, a task that it generally performs very poorly if there are many views in the model.
PickElement prompts the user for interactive element selection, which is not what you are after.
The one and only way to programmatically access elements in the Revit database is to use a filtered element collector:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.9

How can we access dynamically created controls in C# windows application? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am designing C# windows application using 3-Tier architecture, Basically i am making management system for super market in which i have created a form for generating BILL. I have used FlowLayout panel for generating 4 ComboBoxes, 3 TextBoxes and 2 Numeric UpDown respectively to hold Bill values accordingly. I have supplied add button with which we can create these controls dynamically on each button click, so, for example, when user clicks on the add button to add new item, new row will be generated with 4 CBs, 3 TBs and 2 NUpDowns. Having mentioned the scenario, I have following queries:
How can i access each and every of the control in each row in turn? So, for example, I want to access 3rd ComboBox of 5th row, How can I access that in particular.
I am using 3-tier application architecture to design the application. I have placed their functions in BusinessLogicLayer and have called them in UI in button event. Am i alright with this approach?
I want each ComboBox, in each row, to be connected with the first one. for example first one indicates main category when user selects anything from that, second combo box(sub category) should show items connected with the first one and so on. How can i do that?
Thanks
I don't know the very architecture of your application, but let me try and help you. Assumed you have some sort of Customer, Product and Order objects for your business logic the workflow could be the following
void ButtonFindCustomer_Click(object sender, EventArgs e)
{
m_order.Customer = Customer.Find(TextBoxFirst.Text, TextBoxLast.Text, TextBoxCustomerID.Text);
}
void ButtonAddProduct_Click(object sender, Event args)
{
m_order.AddArticle(Product.Find(TextBoxArticleNumber.Text), NumericUpDownArticleAmount.Value);
}
void ButtonSubmit_Click(object sender, EventArgs e)
{
m_order.Place();
}
I used the prefix for the member variable here just for clarity, for the lack on context. In your real code you should avoid it. Furthermore I have omitted the check if the user exists in ButtonFindCustomer_Click, this case should be handled, too. In ButtonAddProduct_Click the case a product is added is handled. Again the existence of the product is assumed, thus you'll have to introduce some error handling here, for example by using something like
if(Product.Exists(productNumber))
{
// add to order
}
else
{
// emit error message
}
The actual transaction is performed in the ButtonSubmit_Click handler. The order is validated and then sent to the data access layer (for example written to a SQL-Database). Once again the error handling is missing, please keep that in mind.
To get to your actual questions:
1) You'll somehow have to keep track the controls you created. If you are always creating them in the same groups, you should consider a user control, which avoids keeping track of which controls belong together. The control could - for example - contain a drop down box for categories, a drop down box for products and a numeric up down for the amount.
class ProductSelector : UserControl
{
... //add controls to user control
public event EventHandler CategoryChanged;
public event EventHandler ProductChanged;
...
public void PopulateCategories(list<string> names, list<string> ids)
{
...
}
public void PopulateProducts(list<string> names, list<string ids)
{
...
}
}
Now any time anything about the product is changed, you'll receive an event and can directly access your user control and all necessary data (if you wrote the functions in ProductSelector). If you want to access the controls in turn, you can either get all controls of type ProductSelector from MainForm.Controls or create a list of all ProductControls you added.
2) Yes, I think you'll be alright with this approach. Somewhere you'll have to access the functions of your BLL and UI event handlers are a good starting point for.
3) Please see me answer to 1).
I hope my explanation met your requirements and answered you questions. Feel free to ask, if I may help you any further.

Can ASP.Net Drop Down List Control Be Used to Navigate to Another Page in Same Site

For an outside of the box idea on a particular site I'm building, I would like to use a drop down list control, which has two inputs: Sponsor1 and Sponsor2. My goal is that when a visitor chooses one of the options, they will go a page for that particular sponsor, and enter a pre-defined code via a textbox w/ a "Next" button, which will take them to yet another page to enter more info.
I'm sort of dividing the site up to have branches, as the sponsors will have visitors (i.e., customers) and the sponsors can keep track of these visitors via the input that will go to a database yet to be made.
As I'm creating this in Asp.Net/C#, I cannot find any examples of this being done, outside an old reference being done with JavaScript - yet the end concept is not the same:
Creating a drop-down list that links to other pages
So is this possible to code something in C# within the code-behind to make this behave as I wish, or must I scrap this idea and just do it another way? Thanks to all in advance!!
Have you tried calling an event when the user selects something on the drop-down list?
Edit: Added more context to where everything goes.
protected override void OnInit(EventArgs)
{
dropDownList.selectedIndexChanged += new EventHandler(ddlIndexChanged);
base.OnInit(ea);
}
//Your Page_Load Here
private void ddlIndexChanged(object sender, EventArgs ea)
{
//This is called when the index is changed, you could redirect here
}

How can I create dynamic controls in response to a button click?

I want to fill an updatepanel with new dynamic controls in response to a button click.
However, I also want to be able to access the values of these dynamic controls in response to an event in one of the controls.
Specifically, I want the button to bring up two dropdownmenus. One of the menus (or both if need be) is in another update panel. I want the first menu in the update panel to change its data in response to a value getting selected in the other menu.
I think my problem is that when I cause a postback with one dropdownmenu I lose the other dropdownmenu because I created it in the button_click handler.
I know I should create dynamic controls in the Page_Init method (or so ive heard) but I only want the controls to show up if the button is clicked. There are other buttons on the page which need to create a different set of dynamic controls.
Thanks.
There are a lot of ways you can handle this, and which approach to take really depends on your project's requirements and your available resources.
The smoothest way to do it that would generally provide the best user experience would be to use a Javascript technique to hide and show controls as the page required them. JQuery is the library I would recommend for this. On the most basic level, you simply wire the control's activation (such as a button_click event) and hide or show a div containing the dynamic content as necessary, like so:
$("#control").show();
// and
$("#control").hide();
Alternatively, you can do this in C# by using the Visible property on many of the normal web controls for ASP.NET. The usual code-behind approach would look something like this:
private void btnControl_Click(object sender, EventArgs e)
{
var dynamicControl1 = FindControl("dynamicControl1");
dynamicControl.Visible = false; // or true, as the case may be
}
This particular approach is mostly attached to code-behinds, though, which I would encourage you to avoid if possible. They are practically impossible to test and will make projects a pain to work in. You can use a similar approach in the MVC3 framework, of course, it will just be a little different how you send and receive the control you are setting to not be visible. The other benefit this has that is kind of nice is that if something is set to not be visible, it tends not to even be displayed in the HTML generated by the templating engine (YMMV depending on the engine, but I know this is true in Razor). So someone viewing the source of your webpage won't be able to see inactive controls, which may or may not be something that appeals to you.
EDIT: I see the problem is less to do with how to display these things, and more with how to create and read them back given on-the-fly input.
I'm sure there's a way to do this with Javascript (which would more than probably be the cleanest and best way to do this), but I'm not good enough with JS to know the answer to that one. The way you would handle this in ASP.NET is make the div you're going to add controls to server-side (by using runat='server', then add what you need there. Again, the trivial code-behind approach would be something like:
private void btnControl_Click(object sender, EventArgs e)
{
foreach(var checkBoxChecked in chkBoxes.Where(x => x.Checked))
{
div.Controls.Add(new WebControl()) // or whatever the heck else it is you need.
}
}
This presumes that you have an IEnumerable<CheckBox> to iterate over, of course. You may also want an IList<WebControl> to keep track of all the junk you're adding. You will also need to make sure the CSS is applied properly to the div for the controls you're adding. And again, code-behinds are pretty awful and I use the example only because it'd be easy to spin up in a project to test for yourself.

tabbed document interface in WPF using only on-board means?

I've seen two threads here about TDI & C#. Both of them didn't really answer the questions I have ...
Since TDIs are pretty much like a standard nowadays, I can hardly imagine, that I have to buy a special control (like AvalonDock or SandDock).
This must be possible with built in the tab-control(?) somehow! I don't need special features like dock- and draggable tabitems. Just open every form in a new tab. Thats it.
Like putting every forms content controls into user controls and by request (button, menu click ...) add a new tab and put the corresponding user control on it ... something like this.
How would you do it? This can't be THAT complicated (even for me) or am I missing something?!
thanks a lot!
Maybe Josh Smith's article on MVVM can give you an idea how to design such user interface. Example being built there is kinda tabbed document interface so you can use it as a starting block.
It's not that hard. It seems hard because there are a lot of different ways to do it.
Try this:
<TabControl x:Name="documentArea"/>
Handler for AddForm button:
private void AddFormClick(object sender, RoutedEventArgs e)
{
object form = GetNewForm();
documentArea.Items.Add(form);
}
That's it. You have to implement GetNewForm() in one of two ways. Have it return a user control that displays the form.
OR better yet, have it return your document that you want to display. Use a DataTemplate to select the controls to use for displaying this document. This method is going to be more complex to set up.

Categories

Resources