finance_teacher
asked on
C# -- DataGridView "AuotSizing" HEIGHT ?
1.jpg and 2.jpg look the same to me.
ASKER
1 has a GRAY gap between the COMPONENTS and SUPPLIERS table.
I want NO gap and allow the COMPONENTS table height to
autogrow / autoshrink like what is doable in Oracle JDeveloper.
Is this doable in VS 2008 dotNet 2 ?
I want NO gap and allow the COMPONENTS table height to
autogrow / autoshrink like what is doable in Oracle JDeveloper.
Is this doable in VS 2008 dotNet 2 ?
OH, ok I see now I was looking at the columns for some reason. Are you using a binding source? The first thing I think of is to hook up to the datasource changed event on the BindingSource for the Components. Inside that event I'd check the total number of rows and adjust the height of the data grid to fit, then call this.PerformLayout()
If you set your MasterGroup object to be Dock Top, then the components tool strip to dock top, then the components datagrid to dock top then the suppliers toolstrip to dock top, then the final data grid to dock Fill... everything should layout with PerformLayout()
If you set your MasterGroup object to be Dock Top, then the components tool strip to dock top, then the components datagrid to dock top then the suppliers toolstrip to dock top, then the final data grid to dock Fill... everything should layout with PerformLayout()
ASKER
Do you have any working examples or URLs so I can learn ?
Do you need an example of how to dock components?
For the code, assuming that you have a a datagrid called dataGridViewComponents that is using bindingSource1 as it's binding source, put this in the DataSourceChanged event of the bindingsource:
private void bindingSource1_DataSourceC hanged(obj ect sender, EventArgs e)
{
this.dataGridViewComponent s.Height = this.dataGridViewComponent s.RowTempl ate.Height * this.bindingSource1.Count;
this.PerformLayout();
}
For the code, assuming that you have a a datagrid called dataGridViewComponents that is using bindingSource1 as it's binding source, put this in the DataSourceChanged event of the bindingsource:
private void bindingSource1_DataSourceC
{
this.dataGridViewComponent
this.PerformLayout();
}
ASKER
I added the below, ran the app, messageboxes displayed, I then changed the parameters again, clicked SUBMIT, and no messageboxes displayed, therefore this is NOT settable via the below EVENTS
(including the "DataSourceChanged" EVENT you talked about above.
How is this doable ?
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
private void gMLCOMPONENTSBindingSource _CurrentCh anged(obje ct sender, EventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Cu rrentChang ed");
}
private void gMLCOMPONENTSBindingSource _DataMembe rChanged(o bject sender, EventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Da taMemberCh anged");
}
private void gMLCOMPONENTSBindingSource _CurrentIt emChanged( object sender, EventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Cu rrentItemC hanged");
}
private void gMLCOMPONENTSBindingSource _DataError (object sender, BindingManagerDataErrorEve ntArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Da taError");
}
private void gMLCOMPONENTSBindingSource _DataSourc eChanged(o bject sender, EventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Da taSourceCh anged");
}
private void gMLCOMPONENTSBindingSource _ListChang ed(object sender, ListChangedEventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Li stChanged" );
}
private void gMLCOMPONENTSBindingSource _PositionC hanged(obj ect sender, EventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Po sitionChan ged");
}
private void gMLCOMPONENTSBindingSource _BindingCo mplete(obj ect sender, BindingCompleteEventArgs e)
{
MessageBox.Show("gMLCOMPON ENTSBindin gSource_Bi ndingCompl ete");
}
(including the "DataSourceChanged" EVENT you talked about above.
How is this doable ?
--------------------------
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
private void gMLCOMPONENTSBindingSource
{
MessageBox.Show("gMLCOMPON
}
Did you register the events with the BindingSource?
I tested my solution so I know it works. We're just missing something here. When you say you "changed the parameters again" what do you mean by that? Changed them from what to what?
I tested my solution so I know it works. We're just missing something here. When you say you "changed the parameters again" what do you mean by that? Changed them from what to what?
ASKER
Yes, they are registered since
I did all EVENT setup via attached.
ran the app, messageboxes displayed,
I then changed the parameters again
** changed "Search by" parameters
clicked SUBMIT, and no messageboxes
displayed, therefore this is NOT
settable via the EVENTS
I am using VS 2008 dotNet 2.0
Please post a before and after image
of you DataGridView automatically
resizing and let me know what dotNet
version you are using.
Thanks
I did all EVENT setup via attached.
ran the app, messageboxes displayed,
I then changed the parameters again
** changed "Search by" parameters
clicked SUBMIT, and no messageboxes
displayed, therefore this is NOT
settable via the EVENTS
I am using VS 2008 dotNet 2.0
Please post a before and after image
of you DataGridView automatically
resizing and let me know what dotNet
version you are using.
Thanks
ASKER
attached
0002.jpg
0002.jpg
OK, I see. I was using 3.5, but the example below I did on 2.0. Don't you have a main binding source for the entire form? Sorry if I wasn't clear but you should bind on the bindingSource for the main part if the Components binding source is just a filtered view of the main one. The actual event that you bind to will depend, good thinking trying to bind to all of them.
Here are screenshots and some sample code. If you need the Form.designer.cs code too let me know. Hope this helps. I think we just need to find the right event depending on your setup. ALSO, I updated the resize code a little bit.
FormRunSizeWith2Items.PNG
FormRunSizeWith4Items.PNG
Here are screenshots and some sample code. If you need the Form.designer.cs code too let me know. Hope this helps. I think we just need to find the right event depending on your setup. ALSO, I updated the resize code a little bit.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bindingSource1_DataSourceChanged(object sender, EventArgs e)
{
this.dataGridView1.Height = this.dataGridView1.RowTemplate.Height * (this.bindingSource1.Count + 1);
this.PerformLayout();
}
private void Form1_Load(object sender, EventArgs e)
{
BindingList<Component> cs = new BindingList<Component>();
cs.Add(new Component() { Name = "First" });
cs.Add(new Component() { Name = "Second" });
//cs.Add(new Component() { Name = "Third" });
//cs.Add(new Component() { Name = "Fourth" });
bindingSource1.DataSource = cs;
}
}
public class Component
{
public string Name { get; set; }
}
}
FormDesignSize.PNGFormRunSizeWith2Items.PNG
FormRunSizeWith4Items.PNG
ASKER
Below still fails.
Maybe I have something preventing this from working in my APP ?
-------------------------- ---------- ---------- ---------- ---------- ---------- --------
1. click on "gML_PKGCOMPONENTSBindingS ource" COMPONENT
2. EVENTS
3. DoubleClick "DataSourceChanged"
4. add below code
this.dataGridView1.Height = this.dataGridView1.RowTemp late.Heigh t * (this.bindingSource1.Count + 1);
this.PerformLayout();
5. add below code to bottom of existing "Form1_Load" method
BindingList<Component> cs = new BindingList<Component>();
cs.Add(new Component() { Name = "First" });
cs.Add(new Component() { Name = "Second" });
//cs.Add(new Component() { Name = "Third" });
//cs.Add(new Component() { Name = "Fourth" });
gML_PKGCOMPONENTSBindingSo urce.DataS ource = cs;
6. add below code to "Form1"
public class Component
{
public string Name { get; set; }
}
7. run app
8. attached displays BLANK "Components"
SECTION on all records
Maybe I have something preventing this from working in my APP ?
--------------------------
1. click on "gML_PKGCOMPONENTSBindingS
2. EVENTS
3. DoubleClick "DataSourceChanged"
4. add below code
this.dataGridView1.Height = this.dataGridView1.RowTemp
this.PerformLayout();
5. add below code to bottom of existing "Form1_Load" method
BindingList<Component> cs = new BindingList<Component>();
cs.Add(new Component() { Name = "First" });
cs.Add(new Component() { Name = "Second" });
//cs.Add(new Component() { Name = "Third" });
//cs.Add(new Component() { Name = "Fourth" });
gML_PKGCOMPONENTSBindingSo
6. add below code to "Form1"
public class Component
{
public string Name { get; set; }
}
7. run app
8. attached displays BLANK "Components"
SECTION on all records
ASKER
attached
0002.jpg
0002.jpg
I can see from the screenshot that it actually worked... You can clearly see that the datagrid size is the same size as the table for components. What you're missing from my original post is that you also need to set the Dock property of everything on your form to TOP (You'll also have to make sure the order is correct. If you have something that is out of order, for example, suppliers ends up above components, then right click on the item and click "send to back" or "send to front" for each item until it's in the correct order.
Also, you can google the property Dock or look in msdn for more information on that. Make sure you also learn the Anchor property as well.
Also, you can google the property Dock or look in msdn for more information on that. Make sure you also learn the Anchor property as well.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.