this.gridControl1.MouseDown += gridControl1_MouseDown;
void gridControl1_MouseDown(object sender, MouseEventArgs e)
{
GridCurrentCell currentCell = this.gridControl1.CurrentCell;
if (currentCell.ColIndex == 5)
{
invoiceForm = new InvoiceForm();
invoiceForm.Load += f_Load;
invoiceForm.ok.Click += ok_Click;
invoiceForm.cancel.Click += cancel_Click;
invoiceForm.ShowDialog();
}
}
void ok_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(invoiceForm.product.Text) && invoiceForm.srno.Text == rowIndex.ToString())
{
this.gridControl1[rowIndex, 1].CellValue = invoiceForm.srno.Text;
this.gridControl1[rowIndex, 2].CellValue = invoiceForm.name.Text;
this.gridControl1[rowIndex, 3].CellValue = invoiceForm.code.Text;
this.gridControl1[rowIndex, 4].CellValue = invoiceForm.party.Text;
this.gridControl1[rowIndex, 5].CellValue = invoiceForm.product.Text;
this.gridControl1[rowIndex, 6].CellValue = invoiceForm.rate.Text;
this.gridControl1[rowIndex, 7].CellValue = invoiceForm.qty.Text;
this.gridControl1[rowIndex, 8].CellValue = invoiceForm.amount.Text;
this.gridControl1[rowIndex, 9].CellValue = invoiceForm.grossamount.Text;
this.gridControl1[rowIndex, 10].CellValue = invoiceForm.discount.Text;
this.gridControl1.Rows.InsertRange(rowIndex+1, 1);
rowIndex++;
invoiceForm.Dispose();
invoiceForm.Close();
}
} |
Hi shkhtk,Thanks for using Syncfusion product.We can understand your scenario. We have prepared the sample based on our requirement by using the custom form (Invoice form) in GridControl. It will show while clicking on the Product column. Please refer to the below code example and the sample,Code example
this.gridControl1.MouseDown += gridControl1_MouseDown;void gridControl1_MouseDown(object sender, MouseEventArgs e){GridCurrentCell currentCell = this.gridControl1.CurrentCell;if (currentCell.ColIndex == 5){invoiceForm = new InvoiceForm();invoiceForm.Load += f_Load;invoiceForm.ok.Click += ok_Click;invoiceForm.cancel.Click += cancel_Click;invoiceForm.ShowDialog();}}void ok_Click(object sender, EventArgs e){if (!String.IsNullOrEmpty(invoiceForm.product.Text) && invoiceForm.srno.Text == rowIndex.ToString()){this.gridControl1[rowIndex, 1].CellValue = invoiceForm.srno.Text;this.gridControl1[rowIndex, 2].CellValue = invoiceForm.name.Text;this.gridControl1[rowIndex, 3].CellValue = invoiceForm.code.Text;this.gridControl1[rowIndex, 4].CellValue = invoiceForm.party.Text;this.gridControl1[rowIndex, 5].CellValue = invoiceForm.product.Text;this.gridControl1[rowIndex, 6].CellValue = invoiceForm.rate.Text;this.gridControl1[rowIndex, 7].CellValue = invoiceForm.qty.Text;this.gridControl1[rowIndex, 8].CellValue = invoiceForm.amount.Text;this.gridControl1[rowIndex, 9].CellValue = invoiceForm.grossamount.Text;this.gridControl1[rowIndex, 10].CellValue = invoiceForm.discount.Text;this.gridControl1.Rows.InsertRange(rowIndex+1, 1);rowIndex++;invoiceForm.Dispose();invoiceForm.Close();}}Sample link: GridControlPlease let us know, if we misunderstood your scenarioRegards,Mohanraj G
Query |
Solution |
when form/web form is loaded it display grid column (A,B,C) as per developer defined column header eg(A will be "Code",B will be "Product Name ", C will be "Rate" and so on ). |
In order to use the header values from the data table, you can use the PopulateHeaders method. Please refer to the below code example,
Code example
this.gridControl1.PopulateHeaders(GridRangeInfo.Cells(0, 1, gridControl1.RowCount, gridControl1.ColCount), dt);
|
when the form is loaded there will be only one o Row + the header columns. |
If you want to load the only one row in grid, you can use the RowCount property. Please rerefer to the below code example,
Code example
this.gridControl1.RowCount = 1; |
now when user is on Code column he will hit enter and new form will be show and he will select the product from that dialog and when clicked on ok the cell value of the current row and column (code,product name ,Rate will be reflected from the selected record ).
and now user is on last column of the row and he hit enter then a new row will be added step(1,2,3,4) follows . |
In order to achieve your scenario, you can use the KeyDown event. Please refer to the below code example
Code example
this.gridControl1.KeyDown += gridControl1_KeyDown;
void gridControl1_KeyDown(object sender, KeyEventArgs e)
{
GridCurrentCell currentCell = this.gridControl1.CurrentCell;
if (currentCell.RowIndex == rowIndex && currentCell.ColIndex == 1 && e.KeyData == Keys.Enter)
{
invoiceForm = new InvoiceForm();
invoiceForm.Load += f_Load;
invoiceForm.ok.Click += ok_Click;
invoiceForm.cancel.Click += cancel_Click;
invoiceForm.ShowDialog();
}
else if (currentCell.ColIndex == 10 && (!String.IsNullOrEmpty(invoiceForm.product.SelectedItem.ToString()) && this.gridControl1[rowIndex,1].CellValue.ToString() == rowIndex.ToString()))
{
this.gridControl1.Rows.InsertRange(rowIndex , 1);
}
} |
i need to the colindex 3 always be checkbook,4 will be date , 5 will be combobox and with databind to that combobox, |
In order to set the CellType for specific columns, you can use the CellType property in QueryCellInfo event. Please refer to the below code example,
Code example
this.gridControl1.QueryCellInfo += gridControl1_QueryCellInfo;
void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.RowIndex > 0)
{
if (e.ColIndex == 3)
{
e.Style.Description = "Male";
e.Style.CellType = "CheckBox";
e.Style.CheckBoxOptions = new GridCheckBoxCellInfo("true", "false", "", false);
}
else if (e.ColIndex == 4)
e.Style.CellValueType = typeof(DateTime);
else if (e.ColIndex == 5)
e.Style.CellType = "ComboBox";
}
} |
i also wont to change the color of the header of the grid.i am going through you documentation. |
In our previous update, we have enabled the themes so only the header color has changed. In order to avoid this settings for grid, you can disable the themes setting by using the ThemesEnabled property. Please refer to the below code example,
Code example
this.gridControl1.ThemesEnabled = false;
|