Home > Net >  C # Winform has two DataGridView control, how to adjust to the right and left of the adaptive
C # Winform has two DataGridView control, how to adjust to the right and left of the adaptive

Time:11-06

C # Winform has two DataGridView control, how to adjust to the right and left of adaptive, want to let them half size, and maximize the form, and drag,

Set up a lot of things, he couldn't do it

CodePudding user response:

Set DockStyle, one on the left, one right, implement INotifyPropertyChanged interface, to create an intermediate variable when the get and set the half width of the form, then the width of the two controls and the intermediate variable bindings, finally in the middle of the form SizeChanged event to set the variable's value,

 
Public partial class Form1: Form, INotifyPropertyChanged
{
The public event PropertyChangedEventHandler PropertyChanged;

Protected void RaisePropertyChanged (string propertyName)
{
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (propertyName));
}

Private int halfWidth;
Public int HalfWidth
{
The get=& gt; HalfWidth;
The set {halfWidth=value; RaisePropertyChanged (nameof (HalfWidth)); }
}

Public _click ()
{
InitializeComponent();
DataGridView1. The Dock=DockStyle. Left;
DataGridView2. The Dock=DockStyle. Right;

DataGridView1. DataBindings. Add (nameof (dataGridView1. Width), and this, nameof (HalfWidth), false, DataSourceUpdateMode. OnPropertyChanged);
DataGridView2. DataBindings. Add (nameof (dataGridView2. Width), and this, nameof (HalfWidth), false, DataSourceUpdateMode. OnPropertyChanged);
}

Private void Form1_SizeChanged (object sender, EventArgs e)
{
HalfWidth=Width/2;
}
}

CodePudding user response:

With a container control SplitContainer or TableLayoutPanel can achieve this requirement, the latter is more flexible, don't need to write any code, all set properties in the design of can,

CodePudding user response:

TableLayoutPanel, two columns each accounted for 50%; TableLayoutPanel itself and two DataGridView DOCK properties are set to FULL

CodePudding user response:

DockStyle

A left, a full
Or
A right, a full

With SplitContainer directly

CodePudding user response:

reference 1/f, small white ah really reply:
Settings DockStyle, a left and a right, implement INotifyPropertyChanged interface, to create an intermediate variable when the get and set the half width of the form, then the width of the two controls and the intermediate variable bindings, finally in the middle of the form SizeChanged event to set the value of a variable,

 
Public partial class Form1: Form, INotifyPropertyChanged
{
The public event PropertyChangedEventHandler PropertyChanged;

Protected void RaisePropertyChanged (string propertyName)
{
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (propertyName));
}

Private int halfWidth;
Public int HalfWidth
{
The get=& gt; HalfWidth;
The set {halfWidth=value; RaisePropertyChanged (nameof (HalfWidth)); }
}

Public _click ()
{
InitializeComponent();
DataGridView1. The Dock=DockStyle. Left;
DataGridView2. The Dock=DockStyle. Right;

DataGridView1. DataBindings. Add (nameof (dataGridView1. Width), and this, nameof (HalfWidth), false, DataSourceUpdateMode. OnPropertyChanged);
DataGridView2. DataBindings. Add (nameof (dataGridView2. Width), and this, nameof (HalfWidth), false, DataSourceUpdateMode. OnPropertyChanged);
}

Private void Form1_SizeChanged (object sender, EventArgs e)
{
HalfWidth=Width/2;
}
}



Public int HalfWidth
{
The get=& gt; HalfWidth;
The set {halfWidth=value; RaisePropertyChanged (nameof (HalfWidth)); }
} here make a mistake

CodePudding user response:

reference 1/f, small white ah really reply:
Settings DockStyle, a left and a right, implement INotifyPropertyChanged interface, to create an intermediate variable when the get and set the half width of the form, then the width of the two controls and the intermediate variable bindings, finally in the middle of the form SizeChanged event to set the value of a variable,

So my window at the top of the panel is covered, what is the way to let it show

CodePudding user response:

Alt + Enter to solve, is not an error

CodePudding user response:

refer to 7th floor really small white ah response:
Alt + Enter to solve of, is not an error

Can be run now, but I'm at the top of the panel is covered, if I set the panel to the top, it covers the following two datagridview header, what to do,

CodePudding user response:

8/f China
references - fu reply:
Quote: refer to 7th floor really small white ah response:
Alt + Enter to solve, is not an error

Can be run now, but I'm at the top of the panel is covered, if I set the panel to the top, it covers the following two datagridview header, what to do,


Is that the top level is wrong, simple operation, the right mouse button "top" or "down"

Of course the insurance operation, the switch to the UI design view, and then the toolbar - view - other Windows - the document outline, open the document outline view, container and control level, drag the control to the appropriate level

CodePudding user response:

When necessary, the new added a panel, drag the hierarchy from the document Outlines the panel to the upper panel, at the same level with you and then the upper set to top, the new set to fill the

Then in the two DGV from document outline, drag to add a panel at a lower level, a set to left, one set to fill
  •  Tags:  
  • C#
  • Related