private void BingDataGridView()
{
dgvItem.Columns.Clear();
dgvItem.ColumnCount = 10;
dgvItem.RowTemplate.Height = 20;
dgvItem.RowHeadersVisible = false;
dgvItem.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgvItem.SelectionMode = DataGridViewSelectionMode.CellSelect;
//Set the column header style.
DataGridViewCellStyle
columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.BackColor = Color.White;
columnHeaderStyle.Alignment = DataGridViewContentAlignment.TopCenter;
columnHeaderStyle.Font = new Font("Arial", 8, FontStyle.Regular);
dgvItem.ColumnHeadersDefaultCellStyle =
columnHeaderStyle;
dgvItem.Columns[0].Name = "S.No";
dgvItem.Columns[1].Name = "Item Name1";
dgvItem.Columns[2].Name = "Item Name2";
dgvItem.Columns[3].Name = "Item Name3";
dgvItem.Columns[4].Name = "Item Name4";
dgvItem.Columns[5].Name = "Item Name5";
dgvItem.Columns[6].Name = "Item Name6";
dgvItem.Columns[7].Name = "Item Name7";
dgvItem.Columns[8].Name = "Item Name8";
dgvItem.Columns[9].Name = "Item Name9";
//add the columnse;
DataGridViewTextBoxColumn
column = new DataGridViewTextBoxColumn();
dgvItem.Columns.Add(column);
dgvItem.Columns[0].ReadOnly = true;
dgvItem.Columns[1].ReadOnly = true;
dgvItem.Columns[2].ReadOnly = true;
dgvItem.Columns[3].ReadOnly = true;
dgvItem.Columns[4].ReadOnly = true;
dgvItem.Columns[5].ReadOnly = true;
dgvItem.Columns[6].ReadOnly = true;
dgvItem.Columns[7].ReadOnly = true;
dgvItem.Columns[8].ReadOnly = true;
dgvItem.Columns[9].ReadOnly = true;
dgvItem.Columns[0].Selected = false;
dgvItem.Columns[1].Selected = false;
dgvItem.Columns[2].Selected = false;
dgvItem.Columns[3].Selected = false;
dgvItem.Columns[4].Selected = false;
dgvItem.Columns[5].Selected = false;
dgvItem.Columns[6].Selected = false;
dgvItem.Columns[7].Selected = false;
dgvItem.Columns[8].Selected = false;
dgvItem.Columns[9].Selected = false;
dgvItem.Columns[0].Width = 30;
dgvItem.Columns[1].Width = 200;
dgvItem.Columns[2].Width = 130;
dgvItem.Columns[3].Width = 70;
dgvItem.Columns[4].Width = 75;
dgvItem.Columns[5].Width = 75;
dgvItem.Columns[6].Width = 90;
dgvItem.Columns[7].Width = 90;
dgvItem.Columns[8].Width = 0;
dgvItem.Columns[9].Width = 0;
dgvItem.Columns[0].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[1].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleLeft;
dgvItem.Columns[2].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[3].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[4].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[5].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[6].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[7].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[8].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[9].DefaultCellStyle.Alignment
= DataGridViewContentAlignment.MiddleCenter;
dgvItem.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[5].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[6].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[7].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[8].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvItem.Columns[9].SortMode = DataGridViewColumnSortMode.NotSortable;
DataGridViewCellStyle columnHeaderStyle1 = new DataGridViewCellStyle();
columnHeaderStyle1.BackColor
= Color.White;
columnHeaderStyle1.Alignment
= DataGridViewContentAlignment.TopCenter;
columnHeaderStyle1.Font
= new Font("Arial", 7, FontStyle.Regular);
foreach (DataRow drItem in
dt1.Rows)
{
int
iCount = (dgvItem.Rows.Count) + 1;
dgvItem.Rows.Add((iCount).ToString(),
drItem[0].ToString(), drItem[1].ToString(), drItem[2].ToString(),
drItem[3].ToString(), strRetQty, strRetUnitPrice, strLineTotal,
drItem[6].ToString(), drItem[4].ToString());
}
}