how can i make italic font based on ISVERIFIKASI value?? if ISVERIFIKASI value is 1 make it all row font to italic and if it is 0 make it to default regular...
Any suggestion?
I suggest you use the GridView.RowStyle event.
using DevExpress.XtraGrid.Views.Grid;
//...
void gridView_RowStyle(object sender, RowStyleEventArgs e) {
GridView view = sender as GridView;
if(e.RowHandle >= 0) {
int value = (int)view.GetRowCellValue(e.RowHandle, view.Columns["ISVERIFIKASI"]);
if(value == 1)
e.Appearance.Font = ...;
}
}
Related
I had a Gridview which contains 3 columns , initially during form load i only two columns will be visible one column will be having data and other having checkbox.
i want when i check a checkbox in particular cell, corresponding to that checkbox the third column cell will be visible, i don't want to complete 3rd column to get visible on checking a check box ,Gridview is hardcoded only rows are dymanic (column1,column2 are set to visible and column 3 is set to invisible)
in below inmage when i m checking checkbox complete thried column is visible,which i don't want
can any one help me in this?
i tried below code but it is making 3rd column visible not, particular cell
public form1()
{
dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Columns[e.ColumnIndex + 1].Visible = true;
}
Well You can try RowCommand event for this but as i see you already have event created for checkbox ,Try to find row Index for particular row and then use Cell number (cell[2]) to find the control and assign its property as visible = false,
Here is the demo I've just tried. It seems to work OK. The whole idea is You can't hide a particular cell in DataGridView. However you can make it hidden as a normal GUI engine will use when it wants to hide any control/element (I think so). You just customize it to paint the cell with the BackgroundColor of your DataGridView. Of course, to make it work, it's not such easy. Here is the code for you:
//First, you have to be sure the whole third column is Visible.
//CellPainting event handler for your dataGridView1
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 2)//This is the Column index you want to hide.
{
object o = e.RowIndex == -1 ? null : dataGridView1[e.ColumnIndex - 1,e.RowIndex].Value;
if (o!=null &&!(bool)o || e.RowIndex == -1 || e.RowIndex == dataGridView1.RowCount - 1)
{
e.Graphics.FillRectangle(new SolidBrush(dataGridView1.BackgroundColor), e.CellBounds);
if(e.RowIndex > -1) dataGridView1[e.ColumnIndex, e.RowIndex].ReadOnly = true;
e.Handled = true;
}
if (o != null && (bool)o)
{
dataGridView1[e.ColumnIndex, e.RowIndex].ReadOnly = false;
}
}
}
//CellContentClick event handler for your dataGridView1
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
UpdateThirdColumCell(e);
}
//CellContentDoubleClick event handler for your dataGridView1
private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
UpdateThirdColumCell(e);
}
private void UpdateThirdColumCell(DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)//The column index of the CheckBox column
{
DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
cell.Value = cell.EditingCellFormattedValue;
dataGridView1.Invalidate();
if ((bool)cell.Value)
{
dataGridView1.CurrentCell = dataGridView1[e.ColumnIndex + 1, e.RowIndex];
}
}
}
//CellStateChanged event handler for your dataGridView1
private void dataGridView1_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)
{
if (e.Cell.ColumnIndex == 2 && e.Cell.Selected)
{
dataGridView1.BeginEdit(false);
}
}
And that's all :)
Yeah ,actually we can't make invisible but i want to give an explianation about it in simple way.using
datagridview.rows(e.rowindex).cells[your column name]=true ;
using this it won't allow the user to enter the data in the textbox.if it is false then we can modify it/enter any text.
datagridview.rows(e.rowindex).cells[your column name].backcolour=color.gray/white/black;
using this we can fill color to a particular textbox which is to be painted when checkbox is true/false;
i have a Telerik GridView with a ComboBox Column, while filtering in this Combobox an appending list dropped down.
Same as the image below...
So i want to make the font of the Append list larger.
How to do it?
RadDropDownList uses different popups for its default items representation and for its auto complete suggest items. Here is an example demonstrating how to change the font of both:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
if (editor != null)
{
editor.DropDownStyle = RadDropDownStyle.DropDown;
RadDropDownListEditorElement element = (RadDropDownListEditorElement)editor.EditorElement;
element.VisualItemFormatting -= element_VisualItemFormatting;
element.AutoCompleteSuggest.DropDownList.VisualItemFormatting -= element_VisualItemFormatting;
//this handles the default drop down formatting - when you press the arrow key to open the drop down
element.VisualItemFormatting += element_VisualItemFormatting;
//this handles the suggest popup formatting
element.AutoCompleteSuggest.DropDownList.VisualItemFormatting += element_VisualItemFormatting;
}
}
void element_VisualItemFormatting(object sender, VisualItemFormattingEventArgs args)
{
args.VisualItem.Font = new Font("Arial", 16);
}
You could either make a CellTemplate with your font, or you could handle the CellFormating event and do something like this:
void radGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
// For all cells under the Account Name column
if(e.CellElement.ColumnInfo.Name == "Account Name")
{
if(e.CellElement.Value != null)
{
System.Drawing.Font newfontsize = new System.Drawing.Font(e.CellElement.Font.FontFamily.Name,20);
for each(GridViewCellInfo cell in e.Row.Cells)
{
e.CellElement.Font = newfontsize;
}
}
}
// For all other cells under other columns
else
{
e.CellElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.Font, Telerik.WinControls.ValueResetFlags.Local);
}
}
Plug in whatever size font you want for the "newfontsize" variable. Also note that, the else statement may not be necessary in your case, but you can reset the font to default using the ResetValue property.
How can I change the font color on gridview of DevExpress?
All the solutions I have found are about changing the forecolor and the backcolor..
I want to have a red font in case a value in a cell is negative.
Any suggestion?
Sign for RowCellStyle event and set ForeColor there
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
if(e.Column.FieldName == "Field2")
{
var data = gridView1.GetRow(e.RowHandle) as Sample;
if(data == null)
return;
if (data.Field2 < 0)
e.Appearance.ForeColor = Color.Red;
}
}
You want to take a look at the conditional formatting rules.
DevExpress Conditional Formatting
How can set icon in Dev express data grid depending on the value returning from Database
Here are the steps.
Add an ImageCollection to your form/window and add some icons 16x16 to it.
Add a column to the Grid for the icons.
Set the column's fieldName to image (whatever
you like).
Set the column's UnboundType to Object.
Add a repositoryItemPictureEdit to
the column's columnEdit.
All the above can be done in the designer. Then do the following
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column == colImage1 && e.IsGetData) {
string someValueFromDatabase = (string)gridView1.GetRowCellValue(e.RowHandle, colOne);
if (someValueFromDatabase == "a") {
//Set an icon with index 0
e.Value = imageCollection1.Images[0];
} else {
//Set an icon with index 1
e.Value = imageCollection1.Images[1];
}
}
}
The key here is handling the CustomUnboundColumnData and the repositoryItemPictureEdit.
Can I change the appearance of a Winforms ComboBox so that a Combobox with DropDownStyle = DropDownList looks more like one that is DropDownStyle = DropDown. The functional difference between them is that the former doesn't allow for user entered values, the problem is that it's default color scheme looks grayed out and doesn't match with textboxes on the same dialog.
you can get DropDown appearance from DropDownList style by changing DrawMode property to DrawMode.OwnerDrawFixed and handling item painting by yourself (thankfully, that's easy). Sample class, implementing this idea:
public class ComboBoxEx : ComboBox
{
public ComboBoxEx()
{
base.DropDownStyle = ComboBoxStyle.DropDownList;
base.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
if(e.State == DrawItemState.Focus)
e.DrawFocusRectangle();
var index = e.Index;
if(index < 0 || index >= Items.Count) return;
var item = Items[index];
string text = (item == null)?"(null)":item.ToString();
using(var brush = new SolidBrush(e.ForeColor))
{
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString(text, e.Font, brush, e.Bounds);
}
}
}
You could try to change the FlatStyle property and see if you get something more to your liking. If you really want it to look like it does with DropDownStyle set to DropDown, you could set the DropDownStyle to DropDown and eat the KeyPress event:
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
Still, I would probably not do this as the appearance of the ComboBox is a visual cue to the user indicating whether they should be able to type in the text area or not.