Is there a way to show more than one datafield in a column when using a datagrid?
Datagrid Web Control in Asp.net , Problems, Issues and FAQs ...lt;%#DataBinder.Eval(Container.DataItem, "Field1").ToString()%> - <%#DataBinder.Eval(Container.DataItem, "Field2").ToString()%>
How can I have an onclick event in the DataGrid for any Column?
Datagrid Web Control in Asp.net , Problems, Issues and FAQs ...lt;asp:DataGrid id="DataGrid1" OnItemDataBound ="ItemDB" DataKeyField ="ProductId" runat="server"></asp:DataGrid> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Protected Sub ItemDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) e.Item.Cells[dc.IndexOf(dc[dcCol.ColumnName])].Attributes.Add("onclick", "javascript:window.open('details.aspx?id= "+strID+"',"+"'MyPage','height=300,width=300')");
How can I enable column selections in a DataGrid?
DataGrid - Windows Forms FAQsHere is a sample ( C# , VB ) that has column selections implemented. It derives a DataGrid, adds a columns selection array list, and maintains this list in an override of OnMouseDown. Then to handle actually drawing the selected columns, it uses a derived...
How do I put a CheckBox in a column of a DataGrid?
DataGrid - Windows Forms FAQsYou create a custom DataTableStyle that contains column styles for each column you want to display. You add the column styles in the order you want them to appear. Here are the steps to add an string column, an int column and a bool check column to a...
How do I create a column of icons in my DataGrid?
DataGrid - Windows Forms FAQsYou need to derive a custom column style, override its Paint method and draw the image. In the attached samples, ( VB and C# ), there are two custom column styles. One style is a stand-alone unbound column that just displays an image. The second custom...
How do I format a date column in a DataGrid?
DataGrid - Windows Forms FAQsIf you have added a table style to your DataGrid (so individual column styles have been generated), then you can use code such as this to set the Format property of the particular column style. [C#] // add format column 3 columnstyle where column 3 holds...
How do I create a column of bitmaps in a DataGrid?
DataGrid - Windows Forms FAQsYou can derive a custom columnstyle and override its Paint method to draw the image. Here are both C# and VB.Net samples . The Paint override offers three ways to draw the bimap in the cell; size it to fit the cell bounds, size it proportionally to fit...
How do I create a ComboBox column in a DataGrid?
DataGrid - Windows Forms FAQsThere are several ways to go about this task. The simplest way involves adding a single combobox to the DataGrid.Controls, and then selectively displaying it as needed when a combobox cell becomes the currentcell. All the work is done in a few event handlers...
How do I automatically size a column in a DataGrid?
DataGrid - Windows Forms FAQsOne way to do this is to use MeasureString to compute the size of the text in each cell, and then take the maximum value. Below is a code snippet that does this. It assumes your datagrid is bound to a datatable. You can download a full working sample...
How do I set the width of a column in a DataGrid?
DataGrid - Windows Forms FAQsTo set a column width, your DataGrid must be using a non-null DataGridTableStyle. Once this is in place, you can set the column width by first getting the tablestyle and then using that object to obtain a column style with which you can set the width...
How do I hide a column in a DataGrid?
DataGrid - Windows Forms FAQsThere are several ways to hide a column: 1) You can use your DataSet's ColumnMapping property to hide a column. // Creating connection and command sting string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb"; string...
How can I put a combobox in a column of a datagrid?
Windows Forms FAQ - Windows Forms DatagridThere are several ways to go about this task. The simplest way involves adding a single combobox to the DataGrid.Controls, and then selectively displaying it as needed when a combobox cell becomes the currentcell. All the work is done in a few event handlers and no overrides or derived classes are necessary. This technique is discussed in Microsoft KB article Q323167. The other techniques require you to derive a columnstyle.
How can I have a column of icons in my datagrid?
Windows Forms FAQ - Windows Forms DatagridYou need to derive a custom column style, override its Paint method and draw the image. In the attached samples, (VB and C#), there are two custom column styles. One style is a stand-alone unbound column that just displays an image. The second custom column style adds the image to the left side of a bound column. In both cases, the actual image that is displayed is from an imagelist passed into the column in its constructor.
How can I autosize a column in my datagrid?
Windows Forms FAQ - Windows Forms DatagridOne way to do this is to use MeasureString to compute the size of the text in each cell, and then take the maximum value. Below is a code snippet that does this. It assumes your datagrid is bound to a datatable. You can download a full working sample. (C#,VB). dataGrid1.TableStyles["customers"].GridColumnStyles[col].Width = (int) width + 8; // 8 is for leading and trailing padding
How can I have a column of bitmaps in a DataGrid?
Windows Forms FAQ - Windows Forms DatagridYou can derive a custom columnstyle and override its Paint method to draw the image. Here are both C# and VB.Net samples. The Paint override offers three ways to draw the bimap in the cell; size it to fit the cell bounds, size it proportionally to fit the cell bounds, and draw it with it's original size (clipping the bitmap to fit in the cell bounds). In the sample, the DataGrid is anchored on all four sides, so as you size the form, the DataGrid sizes as well.
How can I disable sorting for a specific Column in a DataGrid?
ASP .NET FAQ - DataGridDon't specify the SortExpression for the BoundColumn for which you do not want Sorting. This will only work if you have AutogenerateColumns= false.
