我正在寻找在成功拖放操作后禁用DataGridView行的最佳方法。 所以,我已经删除了行并将其标记为使用背景颜色移动。
现在我需要在同一行停用进一步拖放。这可能不删除行吗?
我可以取消选择已删除的datagridview行,但我不能将其标记为“draggable”:
dgvToolPosition.Rows[dgvToolPosition.SelectedRows[0].Index].Selected = false;
有没有办法设置行的属性,避免在已经删除的行的List<DataGridViewRowCollection>
上插入相应的索引?
答案 0 :(得分:0)
将它拍到黑暗中,但是你不能抓住跌落事件并检查你是否已将它移动到同一行?我快速谷歌搜索了该事件,这就是我提出的:
https://msdn.microsoft.com/en-us/library/system.windows.forms.dragdropeffects(v=vs.110).aspx
答案 1 :(得分:0)
避免先前删除的行上的Drag事件的最佳方法是检查我在成功删除操作(package
)上设置的行的唯一属性:
// GET: Ul
public ActionResult Index(int? pageNum, string searchString)
{
pageNum = pageNum ?? 0;
ViewBag.IsEndOfRecords = false;
if (Request.IsAjaxRequest())
{
var customers = GetRecordsForPage(pageNum.Value);
ViewBag.IsEndOfRecords = (customers.Any()) && ((pageNum.Value * RecordsPerPage) >= customers.Last().Key);
return PartialView("_TopEventLi", customers);
}
else
{
LoadAllTopEventsToSession(searchString);
ViewBag.TopEvents = GetRecordsForPage(pageNum.Value);
return View("Index");
}
}
public void LoadAllTopEventsToSession(string searchString)
{
var students = from s in db.TopEvents
select s;
if (!String.IsNullOrEmpty(searchString))
{
students = students.Where(s => s.Location.Contains(searchString)
|| s.Title.Contains(searchString));
}
var customers = students.ToList();
int custIndex = 1;
Session["TopEventi"] = customers.ToDictionary(x => custIndex++, x => x);
ViewBag.TotalNumberCustomers = customers.Count();
}
public Dictionary<int, TopEvents> GetRecordsForPage(int pageNum)
{
Dictionary<int, TopEvents> customers = (Session["TopEventi"] as Dictionary<int, TopEvents>);
int from = (pageNum * RecordsPerPage);
int to = from + RecordsPerPage;
return customers
.Where(x => x.Key > from && x.Key <= to)
.OrderBy(x => x.Key)
.ToDictionary(x => x.Key, x => x.Value);
}
我知道这不是最好的方法,但直到现在它才是我发现的最好的技巧。我仍在寻找DataGridViewRow上的DefaultCellStyle.BackColor
属性设置为false。