Change the visible position of ROWs of ultragrid programmatically - c#

I have an ultragrid with an unbound Boolean column that i had named it "Select".
user can select and deselect a row by checked or unchecked the "Select" cell of that row.
but if the number of the grid rows are very much, its difficult for the user to find all of selected rows.
So i want to send the selected rows to the top of the grid just after the user select them.
but i could not found any property that can help me?

I have found my solution myself:
private void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e)
{
if (e.Cell.Column.Key == "Select" && Convert.ToBoolean(e.Cell.Value))
{
ultraGrid1.Rows.Move(e.Cell.Row, newPosition);
}
}

Related

Filtering an unbound datagridview

I have an unbound DataGridView that is being populated by pulling attributes from selected features in ArcMap as well as user inputs from text boxes. I have the following code below that loops through the DataGridView and makes rows invisible, based on the value of a combo-box matching a cell in a column.
private void comboBoxName_SelectionChangeCommitted(object sender, EventArgs e)
{
string TextVar;
TextVar = comboBoxName.Text;
checkBoxShowAllRows.Checked = false;
foreach (DataGridViewRow df in this.dataGridList.Rows)
{
if (dataGridList.Rows[df.Index].Cells[5].Value.ToString() == (TextVar))
{
dataGridList.Rows[df.Index].Visible = true;
}
else
{
dataGridList.Rows[df.Index].Visible = false;
}
}
}
That works well. However, I have a date column that will be populated on a new row by reading the date in the row above and adding the amount of days that a user puts into a text box. My issue is that even if I filter out rows with the code above, the date code will still look at the invisible row and use that row above. Is there a way to avoid invisible rows in my index? I want to be able to filter different values but not get rid of them. Would the .Visible method of filtering not be preferred in this case?

Show row numbers in GridControl PrintPreview

I have problem with DevExpress GridControl PrintPreview. How can I create column with row numbers in PrintPreview? I need to show ordinal number for each row PrintPreview.
Thanks for help.
I think the easiest way to do this from a direct export is to add an unbound data column:
Go into the grid designer and add a column; name it (colRowNumber or whatever)
Move the column to be the first column in the layout
In the column's properties:
a. set UnboundType to Integer
b. set OptionsColumn.AllowEdit set it to False
Within the grid, create an event for CustomUnboundColumnData
Your code for the CustomUnboundColumnData event should look something like this:
private void gridView1_CustomUnboundColumnData(object sender,
DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column == colRowNumber)
e.Value = e.ListSourceRowIndex + 1;
}
From here, now matter how your grid is ordered or filtered, the "Row Number" column will always contain the 1-based row number of the displayed data.

Datagrid View cells as Boolean values: Using Datagrid view similar to MS Outlook Meeting Schedular

I am trying to develop a time sheet similar to Outlook meeting scheduling thing(Picture attached from internet). I have days as rows and time as columns. I am trying to use cells in Datagrid view such that when user select cell corresponding to day and time i get input by this selection (nothing to be displayed in cells, I just want to use selected cell as my input). I have declared columns as Boolean type so that selected cell corresponds to True and un-selected as False.
foreach (DataGridViewColumn column in this.dataGridView1.Columns)
{
column.ValueType = typeof(Boolean);
}
However I am not sure how to proceed with this, as I have just declared and not initialized Boolean cells. I am looking a way to initialize cells such that no text appears in cells [blank cells which will be highlighted on selection] and I can just take input based upon selection/non selection of cells.
Since you want the selected cells as input you can use DataGridView.SelectedCells (docs here). From the returned collection you can get the row and column of each selected cell, which in your case maps to day and time.
Here's an example:
private void button1_Click(object sender, EventArgs e)
{
DataGridViewSelectedCellCollection cells = this.dataGridView1.SelectedCells;
foreach (DataGridViewTextBoxCell cell in cells)
{
Console.WriteLine("Selected cell: column: {0} row: {1}", cell.ColumnIndex, cell.RowIndex);
}
}
Output when I selected a couple cells in the third column:
Selected cell: column: 2 row: 2
Selected cell: column: 2 row: 1

winform multiple select grid row and get row index of selected rows

I have a databound gridview in my winform. I want to know how to get the index of Currently selected rows i.e multiple rows.
I am able to do this with a single row. but is there a way I can have a checkbox or something in which I can index of multiple rows.
The Image below will help u understand better of my requirement.
First set CellContentClick event to your DataGridView.
dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.onCellContentClick);
For every cell click it will invoke the following method. Here you can create a list and populate it with clicked row index.
public void onCellContentClick(DataGridViewCellEventArgs cell)
{
// Check whether selected cell is check box column, here 0 indicates the check box column.
if (cell.ColumnIndex == 0)
{
bool isChecked = (Boolean) dataGridView[cell.ColumnIndex, cell.RowIndex].EditedFormattedValue;
if(isChecked)
{
// Below will give you the selected cell row index, for multiple rows you can populate those index in list or whatever you convenient with.
cell.RowIndex;
}
}
}
Use DataGridView.SelectedRows property to get all selected rows.
To select multiple rows:
DataGridView.MultiSelect = true;

On edit event how insert a value into the database in the same row as in the gridview?

I have a gridview.
Here are my columns:
The column choose's control is a dropdown with 2 values: yes/no
No Name Choose
1 Meh Yes/No
On edit event I want to insert the selected value of the dropdown in the database of the current edited cell.
protected void GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = ((GridView)sender).Rows[e.RowIndex];
DropDownList ddl = (DropDownList)row.FindControl("DdlChoose");
bool yes = ddl.SelectedValue == "Yes";
SaveData(params); // pseudo-code
}
1st thing first, i'd suggest data binding, and apply changes to the Database as bulks and not one at a time, unless forced to by definition.
2nd, each row have a key, then it is no problem to execute a Update the Row by
UPDATE mytable SET choose=new_value WHERE key_column=rowkey.
EDIT :
DatagridView Binding to SQL Database example can be found : http://csharp.net-informations.com/datagridview/csharp-datagridview-sql-server.htm

Categories