将新数据添加到 Datagridview 时创建标签
Creating a Label when new data is added to Datagridview
当新数据添加到 datagridview
时,是否可以在单独的 flowlayoutpanel
上创建 label
?我所做的是在设计器中创建 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);
}
}
我通过这样做解决了这个问题。
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();
}
}
当新数据添加到 datagridview
时,是否可以在单独的 flowlayoutpanel
上创建 label
?我所做的是在设计器中创建 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);
}
}
我通过这样做解决了这个问题。
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();
}
}