ionas Posted October 31, 2005 Posted October 31, 2005 Hi all, I am trying to enhance the way a datagrid is displayed on the screen, using VB.NET. What I am trying to do is to fill the whole window with raws, lets say 20 raws though the data I retrieve from the data base are only, lets say 10 raws. That means I will have 10 empty raws. Is there a way to do it ? Please advice........ Quote
Diesel Posted November 1, 2005 Posted November 1, 2005 So, you want to make the datagrid raws bigger if there is not enough to fill the datagrid window? if ( (this.dataGrid1.PreferredRowHeight * this.dataGrid1.VisibleRowCount) < this.dataGrid1.Height - 60) { this.dataGrid1.PreferredRowHeight = (this.dataGrid1.Height-60) / this.dataGrid1.VisibleRowCount; } 60 would be the standard blue header and column headers on the datagrid. I don't know how to retrieve those values. For vb, just change 'this' to 'me' and '{' to 'then' and '}' to 'end if' and get rid of the ; Quote
ionas Posted November 2, 2005 Author Posted November 2, 2005 So, you want to make the datagrid raws bigger if there is not enough to fill the datagrid window? if ( (this.dataGrid1.PreferredRowHeight * this.dataGrid1.VisibleRowCount) < this.dataGrid1.Height - 60) { this.dataGrid1.PreferredRowHeight = (this.dataGrid1.Height-60) / this.dataGrid1.VisibleRowCount; } 60 would be the standard blue header and column headers on the datagrid. I don't know how to retrieve those values. For vb, just change 'this' to 'me' and '{' to 'then' and '}' to 'end if' and get rid of the ; NO, I DO NOT WANT TO CHANGE THE HEIGHT OF RAWS. I JUST WANT TO ADD MORE RAWS ON THE SCREEN. FOR EXAMPLE, IF I HAVE 10 RAWS OF DATA THEN ON THE SCREEN I WANT TO HAVE THE FIRST 10 RAWS FILLED WITH DATA AND THE LAST - LETS SAY 15 RAWS - EMPTY (ONLY BORDER LINES). OF COURSE THE EMPTY RAWS WILL NOT BE BOUNDED WITH THE DATA TABLE. Quote
ionas Posted November 2, 2005 Author Posted November 2, 2005 No, I Do Not Want To Change The Height Of Raws. I Just Want To Add More Raws On The Screen. For Example, If I Have 10 Raws Of Data Then On The Screen I Want To Have The First 10 Raws Filled With Data And The Last - Lets Say 15 Raws - Empty (only Border Lines). Of Course The Empty Raws Will Not Be Bounded With The Data Table. Quote
VagabondSW Posted November 2, 2005 Posted November 2, 2005 In that case, you will have to count the rows returned by your query. If that count is less than your minimum number of rows, then you will have to create additional DataRow objects using DbNull.Value and add them to your Rows collection. To prevent the word "null" from appearing in all the empty cells, you will have to create a DataGridTextBoxColumn and set the NullText property to String.Empty. That DataGridTextBoxColumn will have to be added to a DataGridTableStyle, which in turn will be added to the TableStyles collection of your DataTable object. Adding the 'blank' rows should be simple. Here is the code for the ColumnStyles and TableStyles: Private Function GetGridStyle(ByVal table As DataTable) As DataGridTableStyle Dim dcc As DataColumnCollection Dim tableStyle As New DataGridTableStyle dcc = table.Columns For Each column As DataColumn In dcc tableStyle.GridColumnStyles.Add(GetTextBoxColumn(column)) Next With tableStyle .MappingName = table.TableName .ReadOnly = True .AlternatingBackColor = Color.AntiqueWhite .RowHeadersVisible = False End With Return tableStyle End Function Private Function GetTextBoxColumn(ByVal column As DataColumn) As DataGridTextBoxColumn Dim textBoxColumn As New DataGridTextBoxColumn With textBoxColumn .MappingName = column.ColumnName .HeaderText = column.Caption .NullText = String.Empty .ReadOnly = True End With Return textBoxColumn End Function I hope this helps. Quote "Never ascribe to malice that which can adequately be explained by incompetence." -- Napolean Bonaparte
ionas Posted November 3, 2005 Author Posted November 3, 2005 YES, this really helps. The point is I must find a way to identify (or count) the new rows the user could key in or the rows the user decided to delete. In other words, I have on screen a 20 rows table with 15 rows filled with data. If a user, for example, keys in two rows (16,17 rows) I must insert these two rows to DB table. Of course, I do not want to update the whole table (20 rows) because in that case I will have empty rows to the DB table. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.