473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems setting up datagrid

I am attempting to set up a datagrid that will 1) display a subset of data
from a SQL Stored Procedure in a different order form how SQL returns it,
and 2) display 3 of the columns using pulldowns. I have gotten code for
both from the www.syncfusion.com site, but am having trouble making them
work. Below is the relevant code:
' Setup the permissions grid
' Fill the dataset of permissions
Dim dt As DataTable = dsUserData.Tables(0)
' Remove the table columns we don't want to have in the grid
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(0)
dt.Columns.RemoveAt(0)

Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "permissions"

' Setup the Subsystems column
Dim TextCol As New DataGridTextBoxColumn
TextCol.MappingName = dt.Columns(3).ColumnName
TextCol.HeaderText = dt.Columns(3).ColumnName
tableStyle.GridColumnStyles.Add(TextCol)

' Setup the permissions columns
Dim i As Integer
For i = 0 To 2
Dim ComboTextCol As New DataGridComboBoxColumn
ComboTextCol.MappingName = dt.Columns(i).ColumnName
ComboTextCol.HeaderText = dt.Columns(i).ColumnName
ComboTextCol.Width = 120
ComboTextCol.ColumnComboBox.Items.Clear()
ComboTextCol.ColumnComboBox.Items.Add("0")
ComboTextCol.ColumnComboBox.Items.Add("1")
ComboTextCol.ColumnComboBox.Items.Add("3")
ComboTextCol.ColumnComboBox.Items.Add("7")
' ComboTextCol.ColumnComboBox.Items.Add("No Access")
' ComboTextCol.ColumnComboBox.Items.Add("Guest")
' ComboTextCol.ColumnComboBox.Items.Add("Operator")
' ComboTextCol.ColumnComboBox.Items.Add("Manager")

tableStyle.PreferredRowHeight =
ComboTextCol.ColumnComboBox.Height + 2

tableStyle.GridColumnStyles.Add(ComboTextCol)
Next

grdPermissions.TableStyles.Clear()
grdPermissions.TableStyles.Add(tableStyle)
grdPermissions.DataSource = dt
' MsgBox(grdPermissions.TableStyles(0).MappingName)

dsUserData is already setup and is being used to also fill some text boxes
on the form, so I know that it is fine, and I have as part of my project the
DataGridComboBoxColumn.vb class that is defined in the syncfusion web site.
From what I have been able to find, the "Setup Subsystems" section should
make that column be the first in the grid because it is defined first in the
TableStyle, but it is showing up last (as it was in the original dataset).
Also, the 3 column that are setup under "Setup the permissions columns" are
showing up as simple text boxes, not as combo boxes. Can anyone see what I
am doing wrong here?

TIA
Ron L

Nov 21 '05 #1
2 2669
Hi,

Sounds like it is not using your table style. The mapping name is
wrong. Try this instead.
tableStyle.MappingName = dt.tablename.tostring
Ken
--------------------------
"Ron L" <ro**@bogus.Address.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
I am attempting to set up a datagrid that will 1) display a subset of data
from a SQL Stored Procedure in a different order form how SQL returns it,
and 2) display 3 of the columns using pulldowns. I have gotten code for
both from the www.syncfusion.com site, but am having trouble making them
work. Below is the relevant code:
' Setup the permissions grid
' Fill the dataset of permissions
Dim dt As DataTable = dsUserData.Tables(0)
' Remove the table columns we don't want to have in the grid
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(0)
dt.Columns.RemoveAt(0)

Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "permissions"

' Setup the Subsystems column
Dim TextCol As New DataGridTextBoxColumn
TextCol.MappingName = dt.Columns(3).ColumnName
TextCol.HeaderText = dt.Columns(3).ColumnName
tableStyle.GridColumnStyles.Add(TextCol)

' Setup the permissions columns
Dim i As Integer
For i = 0 To 2
Dim ComboTextCol As New DataGridComboBoxColumn
ComboTextCol.MappingName = dt.Columns(i).ColumnName
ComboTextCol.HeaderText = dt.Columns(i).ColumnName
ComboTextCol.Width = 120
ComboTextCol.ColumnComboBox.Items.Clear()
ComboTextCol.ColumnComboBox.Items.Add("0")
ComboTextCol.ColumnComboBox.Items.Add("1")
ComboTextCol.ColumnComboBox.Items.Add("3")
ComboTextCol.ColumnComboBox.Items.Add("7")
' ComboTextCol.ColumnComboBox.Items.Add("No Access")
' ComboTextCol.ColumnComboBox.Items.Add("Guest")
' ComboTextCol.ColumnComboBox.Items.Add("Operator")
' ComboTextCol.ColumnComboBox.Items.Add("Manager")

tableStyle.PreferredRowHeight =
ComboTextCol.ColumnComboBox.Height + 2

tableStyle.GridColumnStyles.Add(ComboTextCol)
Next

grdPermissions.TableStyles.Clear()
grdPermissions.TableStyles.Add(tableStyle)
grdPermissions.DataSource = dt
' MsgBox(grdPermissions.TableStyles(0).MappingName)

dsUserData is already setup and is being used to also fill some text boxes
on the form, so I know that it is fine, and I have as part of my project the
DataGridComboBoxColumn.vb class that is defined in the syncfusion web site.
From what I have been able to find, the "Setup Subsystems" section should
make that column be the first in the grid because it is defined first in the
TableStyle, but it is showing up last (as it was in the original dataset).
Also, the 3 column that are setup under "Setup the permissions columns" are
showing up as simple text boxes, not as combo boxes. Can anyone see what I
am doing wrong here?

TIA
Ron L


Nov 21 '05 #2
Ken
Thanks for the response. I tried that change and get the following
error message when I open the form:

An unhandled exception of type 'System.InvalidCastException'
occurred in system.windows.forms.dll
Additional information: Specified cast is not valid.

I don't know where the table name would come from, but the contents of this
dataset is the results set returned from calling a SQL 2k stored procedure
that does a select on a number of tables using JOIN statements. Do you have
any further suggestions?

Thanks,
Ron L

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Sounds like it is not using your table style. The mapping name is
wrong. Try this instead.
tableStyle.MappingName = dt.tablename.tostring
Ken
--------------------------
"Ron L" <ro**@bogus.Address.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
I am attempting to set up a datagrid that will 1) display a subset of data
from a SQL Stored Procedure in a different order form how SQL returns it,
and 2) display 3 of the columns using pulldowns. I have gotten code for
both from the www.syncfusion.com site, but am having trouble making them
work. Below is the relevant code:
' Setup the permissions grid
' Fill the dataset of permissions
Dim dt As DataTable = dsUserData.Tables(0)
' Remove the table columns we don't want to have in the grid
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(5)
dt.Columns.RemoveAt(0)
dt.Columns.RemoveAt(0)

Dim tableStyle As New DataGridTableStyle
tableStyle.MappingName = "permissions"

' Setup the Subsystems column
Dim TextCol As New DataGridTextBoxColumn
TextCol.MappingName = dt.Columns(3).ColumnName
TextCol.HeaderText = dt.Columns(3).ColumnName
tableStyle.GridColumnStyles.Add(TextCol)

' Setup the permissions columns
Dim i As Integer
For i = 0 To 2
Dim ComboTextCol As New DataGridComboBoxColumn
ComboTextCol.MappingName = dt.Columns(i).ColumnName
ComboTextCol.HeaderText = dt.Columns(i).ColumnName
ComboTextCol.Width = 120
ComboTextCol.ColumnComboBox.Items.Clear()
ComboTextCol.ColumnComboBox.Items.Add("0")
ComboTextCol.ColumnComboBox.Items.Add("1")
ComboTextCol.ColumnComboBox.Items.Add("3")
ComboTextCol.ColumnComboBox.Items.Add("7")
' ComboTextCol.ColumnComboBox.Items.Add("No Access")
' ComboTextCol.ColumnComboBox.Items.Add("Guest")
' ComboTextCol.ColumnComboBox.Items.Add("Operator")
' ComboTextCol.ColumnComboBox.Items.Add("Manager")

tableStyle.PreferredRowHeight =
ComboTextCol.ColumnComboBox.Height + 2

tableStyle.GridColumnStyles.Add(ComboTextCol)
Next

grdPermissions.TableStyles.Clear()
grdPermissions.TableStyles.Add(tableStyle)
grdPermissions.DataSource = dt
' MsgBox(grdPermissions.TableStyles(0).MappingName)

dsUserData is already setup and is being used to also fill some text boxes
on the form, so I know that it is fine, and I have as part of my project
the
DataGridComboBoxColumn.vb class that is defined in the syncfusion web
site.
From what I have been able to find, the "Setup Subsystems" section should
make that column be the first in the grid because it is defined first in
the
TableStyle, but it is showing up last (as it was in the original dataset).
Also, the 3 column that are setup under "Setup the permissions columns"
are
showing up as simple text boxes, not as combo boxes. Can anyone see what
I
am doing wrong here?

TIA
Ron L

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
1
by: Phil Townsend | last post by:
I am using the ItemDataBound event of a Datagrid to color code table cells according to data returned from a SQL stored procedure. At first everything worked, but then I decided to customize the...
3
by: simchajoy2000 | last post by:
Hi, I have been working with datagrids a lot in the past two weeks and I am running across a lot of problems. Maybe there is no way around these problems but I hope there are and someone out...
5
by: Dennis | last post by:
I have a class that inherits from DataGrid. I can set the rowheights in a DataGrid by tappig into the "get_Datagridrows" method. However, this does not work for classes that inherit from...
2
by: KC | last post by:
Why would the code below fail? I'm making a tablestyle, which works fine. I test to see if the style already exist for this datagrid, if it does, remove it before adding the new version. What I...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
0
by: bh | last post by:
I'm trying to edit data in a datagrid through a dropdown list with different id/text values. The problem comes in when I click the edit button & nothing appears to be happening. Did I do...
4
by: Blackbrand | last post by:
I'll start off with what i'm trying to do: i want to search my data programmatically and then jump to the row in the datagrid. My data will almost allways go out of the datagrids bounds so if the...
2
by: ree321 | last post by:
I tried moving an ASP.net project form 1.1 to 2.0. But I am having problems with getting the OnItemDataBound function to run for a datagrid, in 2.0. It only gets called up if AutoGenerateColumns...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.