DataGrid in .Net
-
I am able to fill a dataset and fill the datagrid. The issue that I am having is that I only want certain columns in the data grid. If there is 10 columns in a database, how can I display 3 of them and only them three in a datagrid?:doh: Any suggestions or examples is greatly appreciated. Thanks.:) Beginner in ASP.Net and VB.Net
-
I am able to fill a dataset and fill the datagrid. The issue that I am having is that I only want certain columns in the data grid. If there is 10 columns in a database, how can I display 3 of them and only them three in a datagrid?:doh: Any suggestions or examples is greatly appreciated. Thanks.:) Beginner in ASP.Net and VB.Net
Dim oConn As New OleDbConnection Dim oCmd As New OleDbCommand Some thing like this: Dim oDS As New DataSet Dim oDSNew As New DataSet Dim oDA As New OleDbDataAdapter(oCmd) Dim oCol As New DataColumn Dim oCol2 As New DataColumn Dim oCol3 As New DataColumn Dim oRows As DataRow Dim oTable As New DataTable oConn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=HealthandSafety;Data Source=." oConn.Open() oCmd.CommandType = CommandType.Text oCmd.Connection = oConn oCmd.CommandText = "SELECT * FROM HSDocumentFloorZone" oDA.Fill(oDS) With oDS.Tables(0) oCol = .Columns(1) oCol2 = .Columns(3) oCol3 = .Columns(5) End With oDS.Tables(0).Columns.Clear() oDS.Clear() oDS.Dispose() With oTable .Columns.Add(oCol) .Columns.Add(oCol2) .Columns.Add(oCol3) End With oDSNew.Tables.Add(oTable) With DataGrid1 .DataSource = oDSNew End With Many Thanks Harry
-
I am able to fill a dataset and fill the datagrid. The issue that I am having is that I only want certain columns in the data grid. If there is 10 columns in a database, how can I display 3 of them and only them three in a datagrid?:doh: Any suggestions or examples is greatly appreciated. Thanks.:) Beginner in ASP.Net and VB.Net
Manually add a mapping to those specific columns by adding
columnstyles
to your datagrid. Thecolumnstyles
are accesible through theTableStyle
property at design-time. Note: you will also have to map theTableStyle
to your table
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
Manually add a mapping to those specific columns by adding
columnstyles
to your datagrid. Thecolumnstyles
are accesible through theTableStyle
property at design-time. Note: you will also have to map theTableStyle
to your table
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
Let's say I have a table named "user" and columns "name","sex", "address" in that table, and I want to display only name and sex in the datagrid. Therefore, the mapping name for the tablestyle would be "user", and I'll create two columnstyles with the mapping name "name" and "sex". HTH.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
Let's say I have a table named "user" and columns "name","sex", "address" in that table, and I want to display only name and sex in the datagrid. Therefore, the mapping name for the tablestyle would be "user", and I'll create two columnstyles with the mapping name "name" and "sex". HTH.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
What I have done was mapped the table style to Address and mapped the columns to First, Last, and Work (using First, Last, and Work). This all seems to make sense to me but nothing seems to happen when I load the form. Is there something that I might be missing? Do I have to programatically fill the datagrid using the new tablestyle? Thanks. Beginner in ASP.Net and VB.Net
-
What I have done was mapped the table style to Address and mapped the columns to First, Last, and Work (using First, Last, and Work). This all seems to make sense to me but nothing seems to happen when I load the form. Is there something that I might be missing? Do I have to programatically fill the datagrid using the new tablestyle? Thanks. Beginner in ASP.Net and VB.Net
That's weird. Well this is how I do it. In Design View, I drag the datagrid onto the form. Then on the property grid, click on the ellipse for the TableStyle property. A dialog box will appear. Click Add to add a tablestyle, set the Mapping Name property to your tablename, then click on the ellipse for the gridcolumnstyle property. Another dialog box will appear. Click on Add to add a columnstyle, then set the mapping name to the column you want to show. Repeat this last bit for each column.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
That's weird. Well this is how I do it. In Design View, I drag the datagrid onto the form. Then on the property grid, click on the ellipse for the TableStyle property. A dialog box will appear. Click Add to add a tablestyle, set the Mapping Name property to your tablename, then click on the ellipse for the gridcolumnstyle property. Another dialog box will appear. Click on Add to add a columnstyle, then set the mapping name to the column you want to show. Repeat this last bit for each column.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
So there is nothing to do programatically? I have done the above steps and rechecked them but nothing still happens. Would you mind me zipping up my project and emailing it too you to see if you see the problem? I'm sure there is something that I am doing wrong. Thanks. Beginner in ASP.Net and VB.Net
-
So there is nothing to do programatically? I have done the above steps and rechecked them but nothing still happens. Would you mind me zipping up my project and emailing it too you to see if you see the problem? I'm sure there is something that I am doing wrong. Thanks. Beginner in ASP.Net and VB.Net
-
Sure, go ahead.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
nick.seng@gmail.com Is this your email? I tried to send you a zip file called Address.zip but it came back as illegal attachment. If you want you can contact me via email directly, timothy@myactv.net. Thanks. Beginner in ASP.Net and VB.Net
-
nick.seng@gmail.com Is this your email? I tried to send you a zip file called Address.zip but it came back as illegal attachment. If you want you can contact me via email directly, timothy@myactv.net. Thanks. Beginner in ASP.Net and VB.Net