我使用以下 linq 将数据网格视图绑定到使用以下代码的实体框架查询。
private void EquipmentFinder_Load(object sender, EventArgs e)
{
SetupCategories();
productgridview.RowTemplate.Height = 130;
var products = from prods in axe.product1
select new
{
productid = prods.product_Id, //0
productnam = prods.product_Name, //1
productimage = prods.product_Image, //2
productprice = prods.product_Price,//3
productdescr = prods.product_Description, //4
};
productbindingsource.DataSource = products;
productgridview.DataSource = productbindingsource;
productgridview.Columns[0].Visible = false;
productgridview.Columns[4].Visible = false;
}
我有列产品ID,产品图片,产品名称,产品描述,产品价格..
为了客户的目的,我已经制作了一些列不可见..
现在我想通过单击列标题对列进行排序....
注意:这里 product.image 存储为数据库中的数组字节 ....
我不知道如何比较字节和排序......
任何人都可以帮助解决这个问题......
非常感谢...
修改后的代码:
private void productgridview_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewColumn newcolumn = productgridview.Columns.GetColumnCount(DataGridViewElementStates.Selected) == 1 ? productgridview.SelectedColumns[0] : null;
DataGridViewColumn oldColumn = productgridview.SortedColumn;
ListSortDirection direction;
if (oldColumn != null)
{
// Sort the same column again, reversing the SortOrder.
if (oldColumn == newcolumn &&
productgridview.SortOrder == SortOrder.Ascending)
{
direction = ListSortDirection.Descending;
}
else
{
// Sort a new column and remove the old SortGlyph.
direction = ListSortDirection.Ascending;
oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None;
}
}
else
{
direction = ListSortDirection.Ascending;
}
productgridview.Sort(newcolumn, direction);
newcolumn.HeaderCell.SortGlyphDirection =
direction == ListSortDirection.Ascending ?
SortOrder.Ascending : SortOrder.Descending;
}
得到一个错误:参数 NUll Exception Was Unhandled ..
Value cannot be null.
Parameter name: dataGridViewColumn
任何人都可以帮助解决这个问题......