DevExpress Gridview eingebaut

This commit is contained in:
Christopher Meinhold 2024-08-28 14:24:15 +02:00
parent ac93a0305a
commit 2bdfa76c7e
2 changed files with 57 additions and 22 deletions

View File

@ -57,9 +57,11 @@ namespace Firmendatenbank
btnCRM = new Button(); btnCRM = new Button();
tableLayoutPanel1 = new TableLayoutPanel(); tableLayoutPanel1 = new TableLayoutPanel();
txtStatus = new TextBox(); txtStatus = new TextBox();
dataGridViewWpVersionen = new DataGridView(); gridControl1 = new DevExpress.XtraGrid.GridControl();
gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView();
tableLayoutPanel1.SuspendLayout(); tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewWpVersionen).BeginInit(); ((System.ComponentModel.ISupportInitialize)gridControl1).BeginInit();
((System.ComponentModel.ISupportInitialize)gridView1).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// txtFirmenname // txtFirmenname
@ -277,7 +279,7 @@ namespace Firmendatenbank
tableLayoutPanel1.Controls.Add(txtFirmenname, 1, 1); tableLayoutPanel1.Controls.Add(txtFirmenname, 1, 1);
tableLayoutPanel1.Controls.Add(txtMailadresse, 1, 2); tableLayoutPanel1.Controls.Add(txtMailadresse, 1, 2);
tableLayoutPanel1.Controls.Add(txtAdresse, 1, 3); tableLayoutPanel1.Controls.Add(txtAdresse, 1, 3);
tableLayoutPanel1.Controls.Add(dataGridViewWpVersionen, 0, 0); tableLayoutPanel1.Controls.Add(gridControl1, 0, 0);
tableLayoutPanel1.Dock = DockStyle.Fill; tableLayoutPanel1.Dock = DockStyle.Fill;
tableLayoutPanel1.Location = new Point(0, 0); tableLayoutPanel1.Location = new Point(0, 0);
tableLayoutPanel1.Name = "tableLayoutPanel1"; tableLayoutPanel1.Name = "tableLayoutPanel1";
@ -292,6 +294,10 @@ namespace Firmendatenbank
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F)); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.Size = new Size(1050, 635); tableLayoutPanel1.Size = new Size(1050, 635);
tableLayoutPanel1.TabIndex = 21; tableLayoutPanel1.TabIndex = 21;
// //
@ -304,16 +310,22 @@ namespace Firmendatenbank
txtStatus.Size = new Size(269, 23); txtStatus.Size = new Size(269, 23);
txtStatus.TabIndex = 22; txtStatus.TabIndex = 22;
// //
// dataGridViewWpVersionen // gridControl1
// //
dataGridViewWpVersionen.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; tableLayoutPanel1.SetColumnSpan(gridControl1, 4);
tableLayoutPanel1.SetColumnSpan(dataGridViewWpVersionen, 4); gridControl1.Dock = DockStyle.Fill;
dataGridViewWpVersionen.Dock = DockStyle.Fill; gridControl1.Location = new Point(3, 3);
dataGridViewWpVersionen.Location = new Point(3, 3); gridControl1.MainView = gridView1;
dataGridViewWpVersionen.Name = "dataGridViewWpVersionen"; gridControl1.Name = "gridControl1";
dataGridViewWpVersionen.Size = new Size(1044, 359); gridControl1.Size = new Size(1044, 359);
dataGridViewWpVersionen.TabIndex = 24; gridControl1.TabIndex = 25;
dataGridViewWpVersionen.CellClick += dataGridViewWpVersionen_CellClick; gridControl1.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { gridView1 });
//
// gridView1
//
gridView1.GridControl = gridControl1;
gridView1.Name = "gridView1";
gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
// //
// Form1 // Form1
// //
@ -325,14 +337,17 @@ namespace Firmendatenbank
Name = "Form1"; Name = "Form1";
Text = "Firmendaten verwalten"; Text = "Firmendaten verwalten";
WindowState = FormWindowState.Maximized; WindowState = FormWindowState.Maximized;
Shown += Form1_Shown;
tableLayoutPanel1.ResumeLayout(false); tableLayoutPanel1.ResumeLayout(false);
tableLayoutPanel1.PerformLayout(); tableLayoutPanel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewWpVersionen).EndInit(); ((System.ComponentModel.ISupportInitialize)gridControl1).EndInit();
((System.ComponentModel.ISupportInitialize)gridView1).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
private TableLayoutPanel tableLayoutPanel1; private TableLayoutPanel tableLayoutPanel1;
private TextBox txtStatus; private TextBox txtStatus;
private DataGridView dataGridViewWpVersionen; private DevExpress.XtraGrid.GridControl gridControl1;
private DevExpress.XtraGrid.Views.Grid.GridView gridView1;
} }
} }

View File

@ -8,11 +8,11 @@ namespace Firmendatenbank
public partial class Form1 : Form public partial class Form1 : Form
{ {
private string connectionString = "Server=192.168.178.201;Database=domainchecker;User ID=root;Password=1td5rugut8;"; private string connectionString = "Server=192.168.178.201;Database=domainchecker;User ID=root;Password=1td5rugut8;";
private bool isFirstClick = false;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
LoadWpVersionen(); LoadWpVersionen();
dataGridViewWpVersionen.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
} }
private void LoadWpVersionen() private void LoadWpVersionen()
{ {
@ -34,18 +34,19 @@ namespace Firmendatenbank
} }
} }
dataGridViewWpVersionen.DataSource = dt; //dataGridViewWpVersionen.DataSource = dt;
gridControl1.DataSource = dt;
} }
private void dataGridViewWpVersionen_CellClick(object sender, DataGridViewCellEventArgs e) private void dataGridViewWpVersionen_CellClick(object sender, DataGridViewCellEventArgs e)
{ {
DataGridViewRow row = dataGridViewWpVersionen.Rows[e.RowIndex]; //DataGridViewRow row = dataGridViewWpVersionen.Rows[e.RowIndex];
txtDomain.Text = row.Cells["domain"].Value.ToString(); //txtDomain.Text = row.Cells["domain"].Value.ToString();
txtStatus.Text = row.Cells["status"].Value.ToString(); //txtStatus.Text = row.Cells["status"].Value.ToString();
// Lade bestehende Firmendaten //// Lade bestehende Firmendaten
LoadFirmendaten(txtDomain.Text); //LoadFirmendaten(txtDomain.Text);
} }
private void LoadFirmendaten(string domain) private void LoadFirmendaten(string domain)
@ -137,7 +138,7 @@ namespace Firmendatenbank
private void RefreshGridView() private void RefreshGridView()
{ {
dataGridViewWpVersionen.DataSource = null; //dataGridViewWpVersionen.DataSource = null;
LoadWpVersionen(); LoadWpVersionen();
} }
private void btnCRM_Click(object sender, EventArgs e) private void btnCRM_Click(object sender, EventArgs e)
@ -166,5 +167,24 @@ namespace Firmendatenbank
UseShellExecute = false UseShellExecute = false
}); });
} }
private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
if (isFirstClick)
{
// Überprüfe, ob eine Zeile ausgewählt ist
if (gridView1.FocusedRowHandle >= 0)
{
txtDomain.Text = gridView1.GetRowCellValue(e.FocusedRowHandle, "domain").ToString();
txtStatus.Text = gridView1.GetRowCellValue(e.FocusedRowHandle, "status").ToString();
LoadFirmendaten(txtDomain.Text);
}
}
}
private void Form1_Shown(object sender, EventArgs e)
{
isFirstClick = true;
}
} }
} }