codequest
asked on
Equivalent of GridView Template Field in DataGridView
I'm planning to rewrite a complex one page asp.net app to winform vb.net so I can deploy it as standalone as well as SaaS. I'm just learning winforms, so many questions to follow, starting with some general capabilities:
In the asp.net app, I have a GridView bound through an ObjectDataSource to a custom class Function that outputs a DataTable that is specific to a variety of different conditions.
Inside the Gridview there is only a single TemplateField that I fill with a variety of different formats depending again on different conditions, including different formats on different rows.
In doing so, I've almost completely overridden the GridView postback internals using custom classes. In fact, using callbacks, I only use the GridView content panel as something to fill with custom htlm, and it looks and behaves exactly the same as the postback version. I'd like to use the same appearance and business logic in the winform implementation.
1) Is there something equivalent to the TemplateField in the DataGridView control? If so, where might I learn about it? If not, what might be another approach to achieving the effect in winforms of having different fields according to different data views, and different fields on different row within the same data view? I can see showing and hiding different panels with different DataGridView controls to get some of the effect, however, I haven't found anything indicating that I can customize row content on a row by row basis. Something like putting a panel inside DataGridView field, and building out that panel during the DataGridView.RowDataBound (or equivalent) event?
In most cases there will be at most 100 rows in the dataset, and I would be satisfied with having to rebuild the entire DataGridView content row by row if necessary (which is essentially what I do now in the asp.net Gridview. I just need to know if and how I can access the DataGridView content and modify it, row by row, just before it displays.
Or use some other control or set of controls besides a DataGridView, maybe just a stack of panels inside another scrollable panel? (I just don't know what's possible in vb.net winforms).
Any help with this would be appreciated.
Thanks!
In the asp.net app, I have a GridView bound through an ObjectDataSource to a custom class Function that outputs a DataTable that is specific to a variety of different conditions.
Inside the Gridview there is only a single TemplateField that I fill with a variety of different formats depending again on different conditions, including different formats on different rows.
In doing so, I've almost completely overridden the GridView postback internals using custom classes. In fact, using callbacks, I only use the GridView content panel as something to fill with custom htlm, and it looks and behaves exactly the same as the postback version. I'd like to use the same appearance and business logic in the winform implementation.
1) Is there something equivalent to the TemplateField in the DataGridView control? If so, where might I learn about it? If not, what might be another approach to achieving the effect in winforms of having different fields according to different data views, and different fields on different row within the same data view? I can see showing and hiding different panels with different DataGridView controls to get some of the effect, however, I haven't found anything indicating that I can customize row content on a row by row basis. Something like putting a panel inside DataGridView field, and building out that panel during the DataGridView.RowDataBound (or equivalent) event?
In most cases there will be at most 100 rows in the dataset, and I would be satisfied with having to rebuild the entire DataGridView content row by row if necessary (which is essentially what I do now in the asp.net Gridview. I just need to know if and how I can access the DataGridView content and modify it, row by row, just before it displays.
Or use some other control or set of controls besides a DataGridView, maybe just a stack of panels inside another scrollable panel? (I just don't know what's possible in vb.net winforms).
Any help with this would be appreciated.
Thanks!
ASKER
Thanks for the input. Any thoughts about another approach? Looks like the "stack of panels inside another scrollable panel" will work in a pinch.
Could you show us a snapshot of ur existing webpage. Perhaps that could help to provide a solution.
ASKER
Schematic attached.
As I mentioned, in asp.net the code basically builds each row individually based on the row "type" and other criteria. I can easily see just building one big scrollable panel with a sub-panel (fixed height and width) for each row (ran a quick test on that part), and then putting whatever I need in the sub-panels. I can use the same overall logic for what needs to be added to each sub-panel. The main rewrite effort (other than using different control declarations) is that I would need to calculate positions for each sub-panel control, replacing some positioning actions that are done in asp.net with css. I don't yet understand the basics of winforms like form refresh, but that's got to be in there somewhere, so I would just rebuild the entire "pseudo-datagridview" on each need for refresh. Again, there would rarely be more than 200 records per table (did I say 100 above?), so it would not take that long, and if it did, there would be a reason to build a more compact "view" mode. The callbacks in asp.net on a local machine are effectively instantaneous (for a small test set).
And if there's someway to leverage WinForms internals, I'd be happy to know about it.
(Posting to EE *ALWAYS* helps me think about what I'm doing. I guess I know I'm exposing these problems to a lot of smart people!)
gridview-design-schematic.jpg
As I mentioned, in asp.net the code basically builds each row individually based on the row "type" and other criteria. I can easily see just building one big scrollable panel with a sub-panel (fixed height and width) for each row (ran a quick test on that part), and then putting whatever I need in the sub-panels. I can use the same overall logic for what needs to be added to each sub-panel. The main rewrite effort (other than using different control declarations) is that I would need to calculate positions for each sub-panel control, replacing some positioning actions that are done in asp.net with css. I don't yet understand the basics of winforms like form refresh, but that's got to be in there somewhere, so I would just rebuild the entire "pseudo-datagridview" on each need for refresh. Again, there would rarely be more than 200 records per table (did I say 100 above?), so it would not take that long, and if it did, there would be a reason to build a more compact "view" mode. The callbacks in asp.net on a local machine are effectively instantaneous (for a small test set).
And if there's someway to leverage WinForms internals, I'd be happy to know about it.
(Posting to EE *ALWAYS* helps me think about what I'm doing. I guess I know I'm exposing these problems to a lot of smart people!)
gridview-design-schematic.jpg
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Wow. Thanks for the information CodeCruiser. Will help me also. :)
ASKER
@CodeCruiser: thanks for the input. Great information.
I appreciate I'm stretching the normal parameters of UI. There are two variables that I don't immediately see access to in these articles:
a) variable column width, row by row
b) variable column content, row by row
Options #1 = A way around this would be to have just one column, with one cell type, that had a panel in it, that could be populated with whatever is needed.
The solutions in the links you provided all speak of starting with a DataGridViewColumn, and, for example, a DataGridViewTextBoxCell (for extensive editing).
I appreciate may be stretching the limits of this question: do you see a high level approach to creating a custom cell type that would have only a single panel, that anything could be loaded into?
My guess is that not be simpler that the "pseudo-datagridview" approach in my earlier post. However, it would be good to consider.
I appreciate I'm stretching the normal parameters of UI. There are two variables that I don't immediately see access to in these articles:
a) variable column width, row by row
b) variable column content, row by row
Options #1 = A way around this would be to have just one column, with one cell type, that had a panel in it, that could be populated with whatever is needed.
The solutions in the links you provided all speak of starting with a DataGridViewColumn, and, for example, a DataGridViewTextBoxCell (for extensive editing).
I appreciate may be stretching the limits of this question: do you see a high level approach to creating a custom cell type that would have only a single panel, that anything could be loaded into?
My guess is that not be simpler that the "pseudo-datagridview" approach in my earlier post. However, it would be good to consider.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks for the input. I think it's up to me now to dig into these tutorials and see what I can do. Big help.
Just as a comment, in my case, I'm not sure it would save anything to build and use a highly customized DataGridView column/cell, compared to building my "pseudo-DataGridView" out of panels. I'll have to check out the minor features, like assigning events to buttons and so on. On reflection, the thing I'm building isn't really a "data grid view", it's really an *outline* representation of several different business element types. So there may not be much value add in stretching the DataGridView metaphor to cover it.
I'm getting the idea though that vs.net winforms has been used a LOT, which means lots of smart people have asked for lots of flexibility and options, which have been added through many releases. So, if I can imagine it, probably someone else has too, which means there will be lots of capability to do everything I want to do.
Again, thanks for the help!
Just as a comment, in my case, I'm not sure it would save anything to build and use a highly customized DataGridView column/cell, compared to building my "pseudo-DataGridView" out of panels. I'll have to check out the minor features, like assigning events to buttons and so on. On reflection, the thing I'm building isn't really a "data grid view", it's really an *outline* representation of several different business element types. So there may not be much value add in stretching the DataGridView metaphor to cover it.
I'm getting the idea though that vs.net winforms has been used a LOT, which means lots of smart people have asked for lots of flexibility and options, which have been added through many releases. So, if I can imagine it, probably someone else has too, which means there will be lots of capability to do everything I want to do.
Again, thanks for the help!
Glad to help :-)
The most you can have is a LinkButton Column.