This is a migrated thread and some comments may be shown as answers.

Using custom DataSet

1 Answer 80 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Iron
Pierre asked on 17 Dec 2007, 04:25 PM
Hi, I use your ragGridControl for the first time. I need to display a list of ActiveDirectory Groups in the grid. I create a custom Dataset with 2 colums (Img and Nom) and put the groups in it.

I set the Grid AutoGenerateColum to false and create 2 colum. When I set the datasource to my custom Dataset, I receive a error telling me that the Colum "nom" are alerady in the table...

Here is my code (sorry for the code directly in the post, but for a unkown reason I can't found the "add code" button in your post toolbar.

Dim Srch As New DirectorySearcher

Dim srchResultat As SearchResultCollection

Dim Resultat As SearchResult

 

'AJoute les colones

RadGridGroupes.MasterGridViewTemplate.AutoGenerateColumns =

False

Dim imgCol As New GridViewImageColumn

imgCol.UniqueName =

"Img"

imgCol.HeaderText =

""

imgCol.DataField =

"Img"

RadGridGroupes.MasterGridViewTemplate.Columns.Add(imgCol)

Dim txtCol As New GridViewTextBoxColumn

imgCol.UniqueName =

"Nom"

imgCol.DataField =

"Nom"

imgCol.Width = 200

imgCol.HeaderText =

"Nom"

RadGridGroupes.MasterGridViewTemplate.Columns.Add(imgCol)

 

 

Srch.Filter =

"(&(objectCategory=group))"

srchResultat = Srch.FindAll

 

Dim dtTable As New DataTable

Dim dtRow As DataRow

dtTable.Columns.Add(

New DataColumn("Img", System.Type.GetType("System.String")))

dtTable.Columns.Add(

New DataColumn("Nom", System.Type.GetType("System.String")))

dtTable.TableName =

"Groupes"

For Each Resultat In srchResultat

dtRow = dtTable.NewRow

dtRow.Item(

"Nom") = Resultat.Properties("name")(0)

dtTable.Rows.Add(dtRow)

Next

RadGridGroupes.DataSource = dtTable

End Sub

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 18 Dec 2007, 04:32 PM
Hi Pierre,

Thank you for writing.

In your code you are trying to add the image column twice. The wrong line is the following:

RadGridGroupes.MasterGridViewTemplate.Columns.Add(imgCol)

You should change it to:

RadGridGroupes.MasterGridViewTemplate.Columns.Add(txtCol )

For creating a second text column, please use this code snippet:

Dim Srch As New DirectorySearcher

Dim srchResultat As SearchResultCollection

Dim Resultat As SearchResult

 

'AJoute les colones

RadGridGroupes.MasterGridViewTemplate.AutoGenerateColumns =

False

Dim imgCol As New GridViewImageColumn("Img")

imgCol.UniqueName =

"Img"

imgCol.HeaderText =

""

RadGridGroupes.MasterGridViewTemplate.Columns.Add(imgCol)

Dim txtCol As New GridViewTextBoxColumn("Nom")

imgCol.UniqueName =

"Nom"

imgCol.Width = 200

imgCol.HeaderText =

"Nom"

RadGridGroupes.MasterGridViewTemplate.Columns.Add(txtCol )

Srch.Filter =

"(&(objectCategory=group))"

srchResultat = Srch.FindAll

 

Dim dtTable As New DataTable

Dim dtRow As DataRow

dtTable.Columns.Add(

New DataColumn("Img", System.Type.GetType("System.String")))

dtTable.Columns.Add(

New DataColumn("Nom", System.Type.GetType("System.String")))

dtTable.TableName =

"Groupes"

For Each Resultat In srchResultat

dtRow = dtTable.NewRow

dtRow.Item(

"Nom") = Resultat.Properties("name")(0)

dtTable.Rows.Add(dtRow)

Next

RadGridGroupes.DataSource = dtTable

End Sub


Contact us again if you have any further questions.

Best wishes,
Julian Benkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Pierre
Top achievements
Rank 1
Iron
Answers by
Julian Benkov
Telerik team
Share this question
or