将新数据添加到label
时,是否可以在单独的flowlayoutpanel
上创建datagridview
?我所做的就是在设计器中创建static labels
,我可以将它们从flowlayoutpanel
移到flowlayoutpanel
。
private void control_MouseDown(object sender, MouseEventArgs e)
{
var control = sender as Control;
this.DoDragDrop(control.Name, DragDropEffects.Move);
}
private void panel_DragEnter(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(typeof(string)))
return;
var name = e.Data.GetData(typeof(string)) as string;
var control = this.Controls.Find(name, true).FirstOrDefault();
if (control != null)
{
e.Effect = DragDropEffects.Move;
}
}
private void panel_DragDrop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(typeof(string)))
return;
var name = e.Data.GetData(typeof(string)) as string;
var control = this.Controls.Find(name, true).FirstOrDefault();
if (control != null)
{
control.Parent.Controls.Remove(control);
var panel = sender as FlowLayoutPanel;
((FlowLayoutPanel)sender).Controls.Add(control);
}
}
答案 0 :(得分:0)
我这样解决了这个问题。
foreach (DataGridViewRow row in dgv.SelectedRows)
{
var Id = row.Cells["ID"].Value.ToString();
int leadID;
if (!String.IsNullOrWhiteSpace(Id) && int.TryParse(Id, out ID))
{
Label label = new Label();
label.Text = row.Cells["Name"].Value.ToString();
}
}