I'm using Infragistics ultrawingrid v16.1 in windows application. Below are Row style properties of grid. each cell in row has 3 to 4 lines of data. But it is showing only first line. In below screenshot, first line data is overlapped. I'm expecting the data shown as in second row. Please let me know how to show entire data of a cell. Thanks in advance.
this.grd1.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
this.grd1.DisplayLayout.Override.RowSizing = Infragistics.Win.UltraWinGrid.RowSizing.AutoFree;
this.grd1.DisplayLayout.Override.RowSizingArea = Infragistics.Win.UltraWinGrid.RowSizingArea.EntireRow;
this.grd1.DisplayLayout.Override.RowSizingAutoMaxLines = 5;
You should tell the grid that the cells are multiline cells. To do so set CellMultiLine to true like this:
this.grd1.DisplayLayout.Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.True;
Here is and sample in Infragistics online documentation about this property - "Displaying Multi-Line Cells"
You can leave your settings as is, and hook to the InitializeLayout event, (like wnvko said), by double clicking over the UltraGrid in Design time, and use there the EventArgs to set the CellMultiLine to True like:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
e.Layout.Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.True;
}
Add height to your row below is property to add max height to row
this.grd1.DisplayLayout.Override.MaxRowHeight = 100;
set your required height
Related
I would like to add image as water mark in Data Grid View as shown in attached image.
There is no Data Grid View property for background image to set picture and then set its opacity. I looked for third party to give ability of water mark I found telerik was providing but that is not free.
I need free third party tool for Data Grid View water mark or a way to add watermark myself with out using any tool.
thanks in advance
Try this blog -
http://blogs.msdn.com/b/winformsue/archive/2008/01/02/datagridview-watermark-cell.aspx
If you just want the watermark in an empty cell as the watermark in DataGridView control, then you can paint the content when you draw the cell, the article listed above just said how to customize a watermark column and cell for your DataGridView.
http://www.vb-tips.com/TextAndImageColumn.aspx
If you want to overlay the cells with an image the readability will suffer greatly.
But you can add an Image in a nested Panel and either hide and show it when the first row is added or the last one removed.
Or you could always show it but move it under the last row..
The code for this is simple; the nested Panel however will move out of the DataGridView when to many rows are added.. This example asumes all rows have the same Height.
Set up the nesting:
panel1.Parent = dataGridView1;
panel1.Location = new Point(1, dataGridView1.ColumnHeadersHeight + 1);
Move the panel when necessary:
void panelMove()
{
int rh = dataGridView1.RowCount == 0 ? 0 : dataGridView1.Rows[0].Height;
panel1.Location = new Point(1,
dataGridView1.ColumnHeadersHeight + 1 + dataGridView1.RowCount * rh);
}
For example here:
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
panelMove()
}
private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
panelMove()
}
I am using Devexpress Xtragrid Gridcontrol to show stuff in the grid. Each row shows the values of one object, which is represented as text cell besides two comboboxes. To represent the comboboxes I am using repositoryItemComboBox and ComboBoxItemCollection. I have also defined this event for the gridview
prjGridView_MouseDown(object sender, MouseEventArgs e)
{
var hitInfo = prjGridView.CalcHitInfo(e.Location);
if (hitInfo.InRowCell)
{
int rowHandle = hitInfo.RowHandle;
GridColumn column = hitInfo.Column;
if (hitInfo.Column.Name.Equals("UsersItems"))
{
//Update the cell combobox data
}
How can I get the control in the cell shown in the hitInfo. I need this to update the values of the combobox in that cell, each "UserItems" combobox can have different items.
thanks,
ES
You can use ActiveEditor property of gridview.
var activeEditor = prjGridView.ActiveEditor;
Found a very simple method.
I defined this in the class
private ComboBoxItemCollection phaseColl
within the molusedown event I simply use the RowHandle to extract the correct object that is being represented in the row and update the combobox. I think this is a very simple implementation since one cannot look at multiply controls at the same time this will work.
-es
I have 2 Datagrids with same number of columns
Datagrid1 is displaying only headers,
Datagrid2 is just below it displaying all the data.
In essence, the 2 grid's need to be synchronised to appear as 1 grid.
My issue here is I need to hide the horizontal scrollbar of datagrid1, but display only that for the datagrid2.
When the user scroll's the datagrid2, I need to programmatically synchronise the headers on datagrid1.
Can anyone suggest?
Try this..
dataGridViews1.ScrollBars = ScrollBars.None;
private void dataGridViews2_Scroll(object sender, ScrollEventArgs e)
{
int offSetValue = dataGridViews1.HorizontalScrollingOffset;
try
{
dataGridViews1.HorizontalScrollingOffset = offSetValue;
}
catch { }
dataGridViews1.Invalidate();
}
You can set the DataGridViews ScrollBasr property to hide vertical scrollbar
e.g.
dataGridViews1.ScrollBars = ScrollBars.None;
or see other enumeration value at link
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbars
You can set the VerticalScrollingOffset value to position the Scrolling bar at the index you want. Handle the Scroll event in the second DGV and set this VerticalScrollingOffset for the first DGv. This should help.
I have same concept like you..I have solved it as per folowing : may it help u.
private void dgvHeader_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
{
//When Header Grid Width Changes automatically Below Grid's COLUMN width will be changes
dgvData.Columns[e.Column.Index].Width = e.Column.Width;
}
I'm having a weird issue in a program I'm developing for .NET 3.5 using C# in Visual Studio 2010.
I'm populating a DataGridView with information and I'd like to resize the data grid columns according to the headers, but also allow the user to manually resize the colums if the data is longer than the length of the header value.
So I changed my DataGridView.AutoSizeColumnsMode = ColumnHeader. The DataGridView is now resizing the columns automatically according to the header, but suddenly I find that I can't resize the columns manually with my mouse even though my DataGridView.AllowUserToResizeColumns property is true.
My question is how can I automatically size my data grid view columns while still allowing the user to resize the columns?
I was racking my head on the same issue (more or less) and I couldn't figure it out.
I made sure that the following properties were set
AllowUserToResizeColumns = True
AutoSizeColumnsMode = None
Then in my code, I set the following after I filled my grid with data:
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
The OP would obviously instead use:
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader)
That should have done it, so you auto re-sized the Columns once, but otherwise the AutoSizeColumnsMode is set to None, so the user still has control.
...My problem was that I forgot that the Columns themselves have properties that need to be taken into account as well. I had set most of the columns to have:
AutoSizeMode = AllCells
which was the source of my problem...so I set them to
AutoSizeMode = NotSet
and all is as it should be.
The solution from here coverted to C# and tested:
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
// Size the column header based on the ColumnHeader mode
dataGridView1.Columns[i].AutoSizeMode =
DataGridViewAutoSizeColumnMode.ColumnHeader;
// Store autosized width
int colw = dataGridView1.Columns[i].HeaderCell.PreferredSize.Width;
// Change back to Resize mode
dataGridView1.Columns[i].AutoSizeMode =
DataGridViewAutoSizeColumnMode.None;
// Set width to calculated above
dataGridView1.Columns[i].Width = colw;
}
Just found a better solution from MSDN. Before the DataGridView is displayed, use the AutoResizeColumn function. For example:
void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1.AutoResizeColumn(
i, DataGridViewAutoSizeColumnMode.ColumnHeader);
}
}
The way i do it, is more simple:
First fill your grid with the desired data.
Then, set the following properties (you can also set these in the designer of course)
datagridResult.DataSource = YourDataSourceHere
datagridResult.AllowUserToOrderColumns = true;
datagridResult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
Now, Add the following code, in the eventhandler "Shown" of the form:
private void MainForm_Shown(object sender, EventArgs e)
{
Application.DoEvents();
datagridResult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
}
That's all :)
Use the solution from here:
How do you automatically resize columns in a DataGridView control AND allow the user to resize the columns on that same grid
And instead of using
grd.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
Use:
grd.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
detailsDataGridView.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.AllCells doesn't work?
Found it here.
If that doesn't, you can always manually handle it and just resize the column whenever a cell's data changes to be equal to the largest cell.
The code should be like this , hope this will helpful
datagridView1.Columns[columnindex].AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
Problem: My DataGridView has tall cells because of some images in previous columns. So the ComboBox column shows a ComboBox spread on the whole height (and width) of each cell, which just looks unacceptable.
Question: Is there a way to set the size and location of the ComboBox so that it is centered in each cell and maintains its default size?
Note: From googling around it appears that this might be possible by creating my own custom column to host a ComboBox and override the paint event, but before I go that route I want to make sure that's the only way.
#mlsteeves, thanks for pointing out CellPainting event. I don't know how I managed to overlook it. But here is what I am going with now, seems to provide the result I was looking for:
void DataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == ComboBoxColumnIndex)
{
ComboBox comboBox = this.DataGridView.Controls["ColumnComboBox" + e.RowIndex] as ComboBox;
if (comboBox == null)
{
comboBox = this.GetNewComboBox(e.RowIndex);
comboBox.Name = "ColumnComboBox" + e.RowIndex;
this.DataGridView.Controls.Add(comboBox);
}
if (comboBox != null)
{
comboBox.Width = e.CellBounds.Width - 10;
comboBox.Left = e.CellBounds.Left + ((e.CellBounds.Width - comboBox.Width) / 2);
comboBox.Top = e.CellBounds.Top + ((e.CellBounds.Height - comboBox.Height) / 2);
}
}
}
I just recreated your problem, and I have to admit, that sucks! :)
One way to work around is to go into the properties of your ComboBox column, and change the Display Style to Nothing.
This will cause only the selected text to be displayed when then cell is not being editing, the ComboBox will not show up until you edit the cell.
When your row grows higher, you might want to change the DefaultCellStyle so that Alignment is set to Top Left.
If you want the ComboBox shown when the cell is not being edited, take a look at the CellPainting event, it allows you to customize the look of a cell. That might allow you to draw your ComboBox onto your cell.