Commit 6c8e33f5 kwwwvagaa

修改树表格获取选中行问题

1 个父辈 969d38ae
...@@ -316,15 +316,24 @@ namespace HZH_Controls.Controls ...@@ -316,15 +316,24 @@ namespace HZH_Controls.Controls
if (m_selectRow != null) if (m_selectRow != null)
lst.AddRange(new List<IDataGridViewRow>() { m_selectRow }); lst.AddRange(new List<IDataGridViewRow>() { m_selectRow });
} }
if (Rows != null && Rows.Count > 0) if (Rows != null && Rows.Count > 0 && m_rowType == typeof(UCDataGridViewTreeRow))
{ {
foreach (var row in Rows) foreach (UCDataGridViewTreeRow row in Rows)
{ {
Control c = row as Control; lst.AddRange(FindTreeRowSelected(row));
UCDataGridView grid = FindChildGrid(c); }
if (grid != null) }
lst.AddRange(grid.SelectRows); return lst;
} }
private List<IDataGridViewRow> FindTreeRowSelected(UCDataGridViewTreeRow row)
{
List<IDataGridViewRow> lst = new List<IDataGridViewRow>();
var _lst = row.ChildrenRows.FindAll(p => p.IsChecked);
lst.AddRange(_lst);
foreach (UCDataGridViewTreeRow _row in row.ChildrenRows)
{
lst.AddRange(FindTreeRowSelected(_row));
} }
return lst; return lst;
} }
......
...@@ -313,6 +313,7 @@ namespace HZH_Controls.Controls ...@@ -313,6 +313,7 @@ namespace HZH_Controls.Controls
box.TextValue = ""; box.TextValue = "";
box.Size = new Size(30, 30); box.Size = new Size(30, 30);
box.Dock = DockStyle.Fill; box.Dock = DockStyle.Fill;
box.CheckedChangeEvent += box_CheckedChangeEvent;
c = box; c = box;
} }
else else
...@@ -357,6 +358,11 @@ namespace HZH_Controls.Controls ...@@ -357,6 +358,11 @@ namespace HZH_Controls.Controls
} }
} }
void box_CheckedChangeEvent(object sender, EventArgs e)
{
IsChecked = ((UCCheckBox)sender).Checked;
}
/// <summary> /// <summary>
......
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
{ {
this.ucDataGridView1 = new HZH_Controls.Controls.UCDataGridView(); this.ucDataGridView1 = new HZH_Controls.Controls.UCDataGridView();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// ucDataGridView1 // ucDataGridView1
// //
this.ucDataGridView1.AutoScroll = true;
this.ucDataGridView1.BackColor = System.Drawing.Color.White; this.ucDataGridView1.BackColor = System.Drawing.Color.White;
this.ucDataGridView1.Columns = null; this.ucDataGridView1.Columns = null;
this.ucDataGridView1.DataSource = null; this.ucDataGridView1.DataSource = null;
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
this.ucDataGridView1.IsShowHead = true; this.ucDataGridView1.IsShowHead = true;
this.ucDataGridView1.Location = new System.Drawing.Point(0, 0); this.ucDataGridView1.Location = new System.Drawing.Point(0, 0);
this.ucDataGridView1.Name = "ucDataGridView1"; this.ucDataGridView1.Name = "ucDataGridView1";
this.ucDataGridView1.Padding = new System.Windows.Forms.Padding(0, 40, 0, 0);
this.ucDataGridView1.RowHeight = 41; this.ucDataGridView1.RowHeight = 41;
this.ucDataGridView1.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow); this.ucDataGridView1.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow);
this.ucDataGridView1.Size = new System.Drawing.Size(807, 655); this.ucDataGridView1.Size = new System.Drawing.Size(807, 655);
...@@ -60,10 +61,21 @@ ...@@ -60,10 +61,21 @@
this.label1.TabIndex = 6; this.label1.TabIndex = 6;
this.label1.Text = "*树表格第一列将作为展开缩进处理,请根据实际情况设置具体像素的宽度,请勿使用百分比宽度"; this.label1.Text = "*树表格第一列将作为展开缩进处理,请根据实际情况设置具体像素的宽度,请勿使用百分比宽度";
// //
// button1
//
this.button1.Location = new System.Drawing.Point(591, 677);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(91, 23);
this.button1.TabIndex = 7;
this.button1.Text = "获取选中行";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// UCTestTreeGridTable // UCTestTreeGridTable
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.button1);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.ucDataGridView1); this.Controls.Add(this.ucDataGridView1);
this.Name = "UCTestTreeGridTable"; this.Name = "UCTestTreeGridTable";
...@@ -78,5 +90,6 @@ ...@@ -78,5 +90,6 @@
private HZH_Controls.Controls.UCDataGridView ucDataGridView1; private HZH_Controls.Controls.UCDataGridView ucDataGridView1;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
} }
} }
...@@ -67,5 +67,10 @@ namespace Test.UC ...@@ -67,5 +67,10 @@ namespace Test.UC
AddChilds(model, intCount - 1); AddChilds(model, intCount - 1);
} }
} }
private void button1_Click(object sender, EventArgs e)
{
var c = this.ucDataGridView1.SelectRows.Count;
}
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!