I am using an XtraGridView control in my winform. Now I added a RepositoryItemHyperLinkEdit to it. But I want to show/hide each link according to the row data.
How can I achieve this?
Thanks for any help..
I tried the next code but it did not work, the cell did not be empty.
("Show link" part is ok, but String.Empty does not work)
private void xgvGrid_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (e.Column == gcControlField)
{
if (xgvGrid.GetFocusedRowCellValue("ControlField") != null)
{
if (xgvGrid.GetFocusedRowCellValue("ControlField").ToString() == "LINK")
e.DisplayText = "Show link";
else
e.DisplayText = string.Empty;
}
}
}
You can add your checking in the event GridView.CustomColumnDisplayText.
e.g. Each row is bind to a Person instance
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
// gcLink is your column using repositoryitemhyperlinkedit
if (e.Column == gcLink)
{
var person = gridView1.GetRow(e.RowHandle) as Person;
if (person != null)
{
// Logic to show/hide the link based on other field
if (person.FirstName == "John")
e.DisplayText = string.Empty;
else
e.DisplayText = person.Link;
}
}
}
Related
I am trying to use selectedindex on my gridview if it has a column with an == value to session.
Right now I am only successfull on changing its background color. But how could I also trigger the button If it has similar value on my Session.
private void load_session_value()
{
string trans_id = Session["transaction_id_report"].ToString();
string trans_number = Session["transaction_no_report"].ToString();
//string grid_value_id = GridView1
//string grid_value_num
if (trans_id != null && trans_number != null)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.Cells[1].Text.ToString() == trans_id && row.Cells[2].Text.ToString() == trans_number)
{
row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
GridView1_SelectedIndexChanged(new object(),new EventArgs());
}
}
}
}
This is my current output during page_load
I'm not sure, but i think you are looking for this.
if (row.Cells[1].Text.ToString() == trans_id && row.Cells[2].Text.ToString() == trans_number)
{
row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
//call the Button1_Click method
Button1_Click(new object(), new EventArgs());
}
protected void Button1_Click(object sender, EventArgs e)
{
//do the button click stuff
}
I have a Gridview which has an image column to the right side.When the user checks a checkbox only those items with a non Null Image should be displayed.
I have seen that the Gridview uses the default Image if the database image corresponding to the row is empty.Will i need to write a new stored procedure for this or is there a better way to do it.
I currently have implemented this
try
{
if (checkBox1.Checked == true)
{
dgvGetData.Columns["image"].Visible = true;
foreach (DataGridViewRow row in dgvGetData.Rows)
{
Console.WriteLine("LOOP");
if (row.Cells[16].Value == null)
{
Console.WriteLine("######################################> NULL");
row.Visible = false;
}
else
{
Console.WriteLine("######################################> NOT NULL");
}
}
}
else
{
dgvGetData.Columns["image"].Visible = false;
}
}
catch (Exception error)
{
MessageBox.Show(error.Message);
}
I'd recommend that you use the CellFormatting event handler. You can write a few lines of code to determine if you're on the correct column and then have it display whatever you want.
Here is a partial example:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.Value == null && dataGridView1.Columns[e.ColumnIndex].Name == "Image")
{
dataGridView1.Rows[e.RowIndex].Visible = false;
}
}
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellformattingeventhandler(v=vs.110).aspx
I have a GridLookUpEdit controller and ToolTipController and want to show tooltips for GridLookUpEdit's rows on FocusedRowChanged event.
But i cant find any examples.
Im already tried:
toolTipController1.SetToolTip(MyGridLookUpEdit, "Test");
But tooltip not shown.
private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
ToolTipControlInfo info = null;
GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
object o = hi.HitTest.ToString() + hi.RowHandle.ToString();
string text = "Row " + hi.RowHandle.ToString();
info = new ToolTipControlInfo(o, text);
if (info != null)
e.Info = info;
}
Same result.
What can be wrong?
You need to attach your ToolTipController to underlying GridControl of your GridLookUpEdit:
gridLookUpEdit1.Properties.View.GridControl.ToolTipController = toolTipController1;
Then you can use ToolTipController.GetActiveObjectInfo event to show the tooltip. To get the focused value you can use ColumnView.GetFocusedRowCellValue method or GridView.GetFocusedValue method.
Here is example:
private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
var gridControl = gridLookUpEdit1.Properties.View.GridControl;
if (e.SelectedControl == gridControl)
{
var view = gridControl.GetViewAt(e.ControlMousePosition) as GridView;
if (view != null)
{
object focusedValue = view.GetFocusedRowCellValue(view.Columns[0]);
if (focusedValue != null)
e.Info = new ToolTipControlInfo(view.FocusedRowHandle, focusedValue.ToString());
}
}
}
First make sure you've attached the controller
MyGridLookUpEdit.ToolTipController = toolTipController1;
Then try this
private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
{
GridHitInfo hi = view.CalcHitInfo(e.ControlMousePosition);
if (hi.InRowCell)
{
string text = "Row " + hi.RowHandle.ToString();
e.Info = new ToolTipControlInfo(hi.RowHandle, text);
}
}
I would like by that code to color only the empty cells.
But i'm getting all the cells colored.
Can anybody tell me where's my fault..
private void gridView3_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
if(e.Column.FieldName == "First Name")
{
string category = View.GetRowCellDisplayText(e.RowHandle, View.Columns["First Name"]);
if(category != "")
{
e.CellStyle.BackColor = Color.DeepSkyBlue;
}
}
}
Well for one thing the condition is wrong:
if (category != "")
You are filtering so that the cells that are NOT empty get colored. So replace that with a String.IsNullOrEmpty(category) first.
Next, because you are using DevExpress controls, maybe you could use the built in Conditional Formatting: http://documentation.devexpress.com/#WindowsForms/CustomDocument759
Something like this maybe:
StyleFormatCondition condition1 = new DevExpress.XtraGrid.StyleFormatCondition();
condition1.Appearance.BackColor = Color.DeepSkyBlue;
condition1.Appearance.Options.UseBackColor = true;
condition1.Condition = FormatConditionEnum.Expression;
condition1.Expression = "[First Name] == ''";
gridView1.FormatConditions.Add(condition1);
Your code is coloring non-empty cells (check your condition if(category != ""))
The following works for me:
private void gridView3_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "First Name" &&
string.IsNullOrEmpty(View.GetRowCellDisplayText(e.RowHandle, e.Column)))
{
e.Appearance.BackColor = Color.DeepSkyBlue;
}
}
I am grouping datagrid upto one sub-level.
Like this:
CollectionViewSource pageView = new CollectionViewSource();
pageView.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
pageView.GroupDescriptions.Add(new PropertyGroupDescription("SubCategory"));
tasksDataGrid.ItemsSource = pageView.View;
In my case some records doesn't have Subcategory value.Those records will display under empty row group header of Subcategory in datagrid.
I would like to display directly under Category row group header instead of empty header.
private void TaskDataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)
{
string RowGroupHeader = // how to get currently loading header value
if(RowGroupHeader == string.Empty)
{
e.RowGroupHeader.Height = 0;
}
}
I can't get currently loading RowGroupHeader value.How can i get RowGroupHeader value in LoadingRowGroup event.
Help me on this.
This solved the problem.
private void TaskDataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)
{
var RowGroupHeader = (e.RowGroupHeader.DataContext as CollectionViewGroup);
if (RowGroupHeader != null && RowGroupHeader.Items.Count != 0)
{
MasterTask task = RowGroupHeader.Items[0] as MasterTask;
if (task != null && task.SubCategoryName == null)
e.RowGroupHeader.Height = 0;
}
}
Thanks djohnsonm for your help.
Try this, but insert the name of your VM and Property that would correspond to the Header value.
private void TaskDataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e)
{
string RowGroupHeader = (e.RowGroupHeader.DataContext as ParentVM).VMProperty
if(RowGroupHeader == string.Empty)
{
e.RowGroupHeader.Height = 0;
}
}