Conditional Page Break On XtraReports Table - c#

I have a grid on my XtraReports and i would like to place in a conditional page break my list consist of oranges, Lemons and Apples and their descriptions. how do i iterate through each row and get a Field value for particular column.
i have tried accessing the detail Report which is my grid table name and Get Current Column Value but that is not what i am looking for because row 1 will have apple and row 2 will have lemons so i want to break each time when row 1 column 1 does not match row 2 column 1
private void xrPageBreak1_BeforePrint_1(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
SetBreaks(sender);
}
private void SetBreaks(object sender)
{
XRPageBreak control = sender as XRPageBreak;
var ItemName =
DetailReport.GetCurrentColumnValue("Item").ToString();
if(ItemName == "Apple")
{
control.Visible = true;
}
}
the code above returns "Apple"

Related

DevExpress: Row handle in gridview and returns a single row

I can’t to get the Row Handle in the GridView by the index in the DataTable DataSource.
I need to pass the value at this comand: gridView3.FocusedRowHandle = ????here????;
in short, what I'm doing. I have two datagrids, the first one must show the row highlighted and filtered, when I select information in the second datagrid.
Image by Form
in this example, I selected a row in the second datagrid that contains the value "cod.uniforme" = 15.
So the line was highlighted in red in the first datagrid, but the course was pointed in the 5th row
private void FirstDataGrid_RowStyle(object sender, RowStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.RowHandle >= 0)
{
string CodUniforme = View.GetRowCellDisplayText(e.RowHandle, View.Columns["CODUNIFORME"]);
if (CodUniforme == txtValorGridView.Text)
{
e.Appearance.BackColor = Color.Salmon;
e.Appearance.BackColor2 = Color.SeaShell;
e.HighPriority = true;
}
}
}

Set an Elements Visibility Based on Cell Value of Bound Datatable

I'm trying to figure out a way in which a cell in a GridView is visible based on it's associated column in the bound DataTable. The issue I believe I'm having is that this table is dynamic and perhaps as rows are added to the table, the table is not being re-populated/re-freshed on the asp page.
Here is the scenario:
I have a table, for example, of three columns and one row. Column 1 is the index, column 2 is a name, column 3 is true or false which is meant to set the visibility of a link in the asp page.
Row 1 is already set as 1, John Doe, false so on the asp page all you see is
1 | John Doe
You can hit a drop down, click a name, and then add this name to the datatable. By default column 3 is inserted with a true value. So after the row is inserted into the table the row is reflected on the asp page as so
1 | John Doe
2 | Jane Doe
But because column 3 is true, I would like a 'delete' button to be visible so the asp page would instead look something like this
1 | John Doe
2 | Jane Doe | Delete
Where 'Delete' is a link for deleting that newly inserted row.
I've found this thinking this is exactly what I need but the 'Delete' link still fails to display in the GridView.
What am I overlooking so that I can simply display an asp:LinkButton (or any link equivalent) based on a cell value in a DataTable?
Edit
Addition of RowDataBound eventhandler function.
protected void NamesGV_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Header) {
for (int i = 0; i < e.Row.Cells.Count; i++) {
e.Row.Cells[i].BackColor = System.Drawing.Color.Beige; ;
}
}
}
So something like this...not tested so you may need to tweak it a bit:
protected void NamesGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].BackColor = System.Drawing.Color.Beige;
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Get reference to the button you want to hide/show
LinkButton delButton = CType(e.Row.Cells(2).FindControl("lbYourLinkButtonId"), LinkButton);
//check your data for value
bool visible = (bool)DoACheckForAValue(NamesGV.DataKeys(e.Row.RowIndex).Value);
delButton.Visible = visible;
}
}

Adding a single row with a single column of one datagridview into another datagridview of multiple column

I have defined a datagridview with 5 columns and another with 1 column ..what i want to do it is on the click of the button in the datagridview with the columns, the row with the single column of the other datagridview pops up..is it possible?..this is the screenshot of my datagridview..
i want to add a datarow of another datagridview with only one column..i know how to handle cellevent but what i really want is the addition of datarow with only one column..
Hope this helps:
private void dgv1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
int newRow = dgv2.Rows.Add();
dgv2.Rows[newRow].Cells[0].Value = dgv1.Rows[e.RowIndex].Cells["Stringtext"].Value;
}
}
This should take the value from the StringText cell and place it in the first column of a newly created row in the second grid when the button in cell 4 is clicked in the first grid.
EDIT:
private void dgv1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
dgv1.Rows[e.RowIndex].Cells["Stringtext"].Value = dgv2.Rows[{y}].Cells[0].Value;
}
}
This one should set the value of the cell "StringText"(which can be changed to whatever you need it to be) in dgv1 to the value of the cell in dgv2 with the rowIndex {y}.

Cant catch errors when editing

I'm kinda new to c# and winforms and need some help.
I've created a dataset and insert it 2 tables "order_lines" and "products". i have a datagridview with columns taken from the table "order_lines" which is an empty table (with no data) .
So in the datagridview i have 3 empty columns: quantity, product (which is a combobox taken from the other data set table products) and a column total which I've created myself (all other columns such as product_id and order_num are invisible).
I'm trying to allow the user to edit and insert data in the datagridview to the columns quantity (insert number) to the column product (choose product from combobox) and the total should be a calculation of the quantity*product_price (according to the product selected from the combobox each product have an id and the price should be taken from the table products according to the product id)
I have 2 problems:
I'm trying to check the user inserted data with the cell_validating event and the data_error
but it doesnt work and instead of getting my error message when the user put invalid data i get an the exception "object cannot be cast from dbnull to other types" which i dont understand why
I don't seem to manage to take the price from the dataset table products and use it in the total column according to the product selected (in the datagridview which show the dataset table "order_lines" theres a hidden column "product_id" also in the dataset table "products" i have the column "product_id" and "product_name" which is the combobox in the datagridview) when a user choose a product i need to get the price.
I hope i managed to explain my question, any ideas will be highly appreciated
This is how I suggest you to do it:
DataTable products;
public Form1()
{
InitializeComponent();
// handle cell changes
dataGridView1.CellValueChanged += dataGridView1_CellValueChanged;
// used for manually raising the ComboBox change
dataGridView1.CurrentCellDirtyStateChanged += dataGridView1_CurrentCellDirtyStateChanged;
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
// return if the row or column headers were changed
if (e.RowIndex < 0 || e.ColumnIndex < 0)
return;
if (e.ColumnIndex != dataGridView1.Columns["total"].Index)
{
var value = 0;
// get the product id from the ComboBox
var product = dataGridView1.Rows[e.RowIndex].Cells[dataGridView1.Columns["Product"].Index].Value;
// get the quantity
var quantity = dataGridView1.Rows[e.RowIndex].Cells[dataGridView1.Columns["TotalQuantity"].Index].Value.ToString();
if (product != null && !String.IsNullOrEmpty(quantity))
{
value =
int.Parse(quantity) *
int.Parse(products.Select("product_id = " + product.ToString())[0]["product_price"].ToString());
dataGridView1.Rows[e.RowIndex].Cells[dataGridView1.Columns["total"].Index].Value = value;
dataGridView1.Invalidate();
}
}
}
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}

first locating, then changing the value of a cell in a selected row in a datagridview?

Im trying figure out how I can change the value of a specific cell in a selected row of a datagridview. I am able to change the value but not in the highlighted row, only the first one. The hghlighting of the row is defined in the "find" button code.
For example: I enter a text, it search each row for that text in the specific column and then scrolls to and highlights/selects the entire row. (This Works Fine)
I then want to be able to get the value of a specific cell of the highlighted row by selecting the column name already present in the dropdownlist(combobox). It then gets the value of that cell and deducts from it a value present in a numericalUpDownCounter(nudQTY).
So far i can do this for different cells selected by column name (cbSupplList) but it only does it for the first row not the highlighted row defined by the "Find" button Code.
The following is my attempt so far:
private void btnFind_Click(object sender, EventArgs e)
{
/* Code to search the alphanumneric Part Number (in Column1 header called "PART NUMBER")
and highlihgt the row*/
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// Removes the row selection
row.Selected = false;
var cellValue = row.Cells["PART NUMBER"].Value;
if (cellValue != null && cellValue.ToString() == tbPartNum.Text.ToUpper())
{
// Scrolls the found row up and highlights the entire row
row.Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = row.Index;
}
}
}
private void btnSold_Click(object sender, EventArgs e)
{
int cellVal;
int newCellVal;
cellVal = Convert.ToInt32(dataGridView1.CurrentRow.Cells[cbSuppList.Text.ToString()].Value);
newCellVal = Convert.ToInt32(cellVal - nudQty.Value);
dataGridView1.CurrentRow.Cells[cbSuppList.Text.ToString()].Value = newCellVal;
}
It seems it may have to do with the SELECTED ROW in the "Find" code and the CURRENT ROW in the "Sold" Code. Making the SELECTED.ROW = CURRENT.ROW would solve it.... any ideas?
You are deselecting only Rows but no Cells.
dataGridView1.CurrentRow - "Gets the row containing current cell"
And Current Cell remains what it was = first cell of a first row.
In order to clear all selected rows/cells use
dataGridView1.ClearSelection()
And instead of
row.Selected = true;
use
row.Cells["PART NUMBER"].Selected = true;
As currently you are selecting only row but not the cell.
I hope this helps...
Otherwise you might want to find relevant cell in btnSold_Click() the same way you did in btnFind_Click()
.
.
EDIT
complete solution for you
private void btnSold_Click(object sender, EventArgs e)
{
int cellVal;
int newCellVal;
cellVal = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[cbSuppList.Text.ToString()].Value);
newCellVal = Convert.ToInt32(cellVal - nudQty.Value);
dataGridView1.SelectedRows[0].Cells[cbSuppList.Text.ToString()].Value = newCellVal;
}
I've just replaced CurrentRow with SelectedRows[0] and works fine.

Categories