Solved

Dynamic DataSource

Posted on 2006-11-10
16
517 Views
Last Modified: 2008-02-01
Hi,
   I am trying to create a DataGridView that is bound to my database.  I've added a DataSource and, when I bind to it, the data displays properly.  However, I would like to have this DataSource change depending on what item is selected in a neighboring TreeView.  So, if I select item1 in the TreeView, the DataGridView's DataSource is filtered on the value of item1.  If I select item2, the DataSource is filtered on the value of item2.  I know how to do this programatically, just wondering if there is a way to do it via VS.NET drag-and-drop.
0
Comment
Question by:DrLondes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 24

Accepted Solution

by:
Justin_W earned 500 total points
ID: 17916581
> I know how to do this programatically, just wondering if there is a
> way to do it via VS.NET drag-and-drop.
Yes and no.

You can't really do it with no coding at all. However, if this is something that you will have to do often, then you could create a custom DataSource Parameter control (coding it only once), and then use that control to do what you described above with no further coding thereafter.

See these links for more info on custom DataSource Parameter controls:
http://weblogs.asp.net/scottgu/archive/2006/01/23/436276.aspx
http://aspnet.4guysfromrolla.com/articles/110106-1.aspx
0
 

Author Comment

by:DrLondes
ID: 17916762
So, create a custom Parameter control, bind that to my TreeView, and pass the parameter to my DataSource?
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17917061
You would include the Parameter's tag inside the DataSource's tag, and that would cause the Parameter's value (which it would retrieve using your custom code) to be passed automatically to the DataSource.

That way, you don't have to write any code when you use the parameter, you just tell the DataSource to use that parameter, and the parameter does the rest itself.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:DrLondes
ID: 17917255
What happens when the TreeView selection is changed?  I would have to manually rebind the DataGridView, no?  I was hoping there was some way to have this all taken care of automatically through databinding.  For instance, I'm pretty sure I've seen code where a dropdown is bound to a particular table and whenever the dropdown selection is changed, a datagrid on the page automatically updates according to the value in the dropdown.  Can't this be done?  Something to do with the BindingContext perhaps?
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17917281
That os because in those cases the DataSource uses a built-in Parameter that monitors the DropDown's selection. That is essentially what you would be doing with the TreeView.
0
 

Author Comment

by:DrLondes
ID: 17917327
Ok, why can't I do that with TreeView then?

Just so I can put this all into perspective then, can you either explain or send me a link about how to do this with a DropDown instead of a TreeView?

Thanks for your help with all this.
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17917384
Check out this link:
http://msdn2.microsoft.com/en-US/library/xt50s8kz.aspx

After reviewing it, the "ControlParameter" Parameter might work for you because it does work with TreeViews, but it will depend on exactly what you are doing with it on your page.
0
 

Author Comment

by:DrLondes
ID: 17917499
I should note, I am using WinForms, not using ASP.NET.
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17917572
In that case, I don't think you can do it via drag-and-drop, unless you create either a custom DataSource or a custom TreeView, and put some code in there. The principal would then be similar to the creation of a Parameter control, but built into either the custom DataSource or custom TreeView.
0
 

Author Comment

by:DrLondes
ID: 17917632
"That os because in those cases the DataSource uses a built-in Parameter that monitors the DropDown's selection."

Can you point me to an example?
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17917806
I was refering to ASP.NET DropDowns, but see the example section of this page:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.controlparameter.aspx
0
 

Author Comment

by:DrLondes
ID: 17917940
So then there is no drag-drop way to set up a WinForm where a databound dropdown determines the data that is displayed in a datagrid?  What is the key difference between ASP.NET and WinForms in this case?
0
 

Author Comment

by:DrLondes
ID: 17917993
http://www.akadia.com/services/dotnet_databinding.html

The "Automatically synchronized Master-Detail" example looks similar to what I want.  I just don't see how the datagrid is tied to the combobox.  How does the datagrid know to update when the selectedindex is changed?
0
 

Author Comment

by:DrLondes
ID: 17918779
This article is very informative and, I think, more along the lines of what I want to do.

http://msdn.microsoft.com/msdnmag/issues/02/02/cutting/
0
 

Author Comment

by:DrLondes
ID: 17921755
Actually, I do want to go with you suggestion.  I've decided to go with a listbox instead of a treeview.  Although this lets me bind to the database and set up a master/detail relationship with a dataGridView, I want to be able to select multiple rows in the ListBox and have the DataGrid display filtered on those rows.  The custom parameter seems perfect for this because I can create a comma-separated list of IDs in the ListBox and use it as a Values list in the DataGridView's Select.  Not as automagic as Mater/Details, but far more flexible.  Thanks!
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17931217
You're welcome.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio hangs on running project 6 84
Data organization issue 7 56
Excel Web Add-in Where is Visual Basic used 9 81
What is needed to become a DBA? 7 56
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question