473,461 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

datagrid filled from a list

Sam
Hi,
Do you know where I can find a simple example of what I'm trying to
achieve :
I have a dataset filled with two columns from a table of my database.
Then the dataset is used to fill a datagrid.
But I would like to store the data of the dataset in a list. My dataset
has 1 column of integer values and 1 column of string values, so my
list should have the same.
Then the datagrid should be filled using the list instead of the
dataset.
I don't know :
-how to create a list and store my dataset's values
-how to specify a list as the datasource for my datagrid

can you help ?
Thx

Nov 21 '05 #1
12 1165
Sam,

I have seen on first sight, crazy questions, yours is one on the top.

However probably you have a reason for it that I don't know, can you explain
that to me, because it makes me very curious and maybe there is a much
simpler solution.

Cor
Nov 21 '05 #2
Sam
yes it sounds crazy...
My problem is that I have comboboxes in my datagrid. When the user
selects a value in one combobox, then the comboboxes on the rows below
should not contain that value any more. So basically the datasource is
getting updated for the row below. In my opinion this is impossible to
achieve as you can have only one datasource per datagrid (and not per
row). Therefore I'd like to populate my comboboxes dynamically from a
list that I would update accordingly ....
Is this possible ? Have you seen similar stuff before ?
thx

Nov 21 '05 #3
Sam,

I believe that you will not succeed logical in this. See this
1 2
2 3
3 4

You change row 1 the 2 in 3 what should than happen in row 2.
(While row 2 is actually not even in action so there happens nothing).

This will be a very lonly route to go in my opinon.

Cor
Nov 21 '05 #4
Sam
If you have a better idea, let me know !
Indeed it's going to be a long route to go but i'm short in time, so if
there's a better way to do that... give me a shot
thx

Nov 21 '05 #5
Sam
In fact, you should not be able to change the 2 in 3 to row 1. Sorry
for my misunderstanding. When you select a value in a combobox, this
value should disappear from all the other combobox of this column.
Is it clearer ?

Nov 21 '05 #6
Sam,

I think I got it as you wanted it.
See here the sample, needs only a form and a datagrid and than pasting this
in.
(at the end you will than have to remove a end class and something)
It is of course a little bit rougly done, however I tried it.

\\\
Private dt As New DataTable("Names")
Private Sub Form1_Load(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Name")
dt.Columns.Add("Country")
dt.LoadDataRow(New Object() {"Cor", "Holland"}, True)
dt.LoadDataRow(New Object() {"Ken", "Florida"}, True)
dt.LoadDataRow(New Object() {"Terry", "England"}, True)
Dim mylist As String() = {"Holland", "Florida", "England",
"Germany"}
Dim dv As New DataView(dt)
dv.AllowNew = False
DataGrid1.DataSource = dv
Dim ts As New DataGridTableStyle
ts.MappingName = "Names"
Dim textCol As New DataGridTextBoxColumn
textCol.MappingName = "Name"
textCol.HeaderText = "Name"
textCol.Width = 120
ts.GridColumnStyles.Add(textCol)
Dim cmbTxtCol As New DataGridComboBoxColumn(mylist, dt)
cmbTxtCol.MappingName = "Country"
cmbTxtCol.HeaderText = "Countries"
cmbTxtCol.Width = 100
ts.GridColumnStyles.Add(cmbTxtCol)
ts.PreferredRowHeight = (cmbTxtCol.ColumnComboBox.Height + 3)
cmbTxtCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList
DataGrid1.TableStyles.Add(ts)
End Sub
'make dataset
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

End Sub
End Class
' The simple DatagridCombobox
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
Public WithEvents ColumnComboBox As NoKeyUpCombo 'special class
Private WithEvents cmSource As CurrencyManager
Private mRowNum As Integer
Private isEditing As Boolean
Private mylist As Object()
Private myDatatable As DataTable
Public Sub New(ByVal list As String(), ByVal dt As DataTable)
MyBase.New()
mylist = list
myDatatable = dt
ColumnComboBox = New NoKeyUpCombo
AddHandler ColumnComboBox.SelectionChangeCommitted, _
New EventHandler(AddressOf ComboStartEditing)
End Sub
Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager,
_
ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal readOnly1 As
Boolean, _
ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, readOnly1, instantText,
cellIsVisible)
Me.ColumnComboBox.Items.Clear()
For Each str As String In mylist
Dim dt() As DataRow = myDatatable.Select("Country = '" & str &
"'")
If dt.Length = 0 Then
ColumnComboBox.Items.Add(str)
End If
Next
ColumnComboBox.Items.Add(Me.TextBox.Text)
mRowNum = rowNum
cmSource = source
ColumnComboBox.Parent = Me.TextBox.Parent
ColumnComboBox.Location = Me.TextBox.Location
ColumnComboBox.Size = New Size(Me.TextBox.Size.Width,
ColumnComboBox.Size.Height)
ColumnComboBox.Text = Me.TextBox.Text
TextBox.Visible = False
ColumnComboBox.Visible = True
ColumnComboBox.BringToFront()
ColumnComboBox.Focus()
End Sub
Protected Overloads Overrides Function Commit(ByVal dataSource As _
CurrencyManager, ByVal rowNum As Integer) As Boolean
If isEditing Then
isEditing = False
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text)
End If
Return True
End Function
Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As
EventArgs)
isEditing = True
MyBase.ColumnStartedEditing(DirectCast(sender, Control))
End Sub
Private Sub LeaveComboBox(ByVal sender As Object, ByVal e As EventArgs)
_
Handles ColumnComboBox.Leave
If isEditing Then
SetColumnValueAtRow(cmSource, mRowNum, ColumnComboBox.Text)
isEditing = False
Invalidate()
End If
ColumnComboBox.Hide()
End Sub
End Class
Public Class NoKeyUpCombo
Inherits ComboBox
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg <> &H101 Then
MyBase.WndProc(m)
End If
End Sub
End Class
///

I hope this helps,

Cor

Nov 21 '05 #7
Sam
thx
your example is great.
I'll probably use it for starting

Nov 21 '05 #8
Sam
Cor,

In the code you sent me, your datagrid combo box inherits from
DataGridTextBoxColumn, wheras mine inherits from combobox. Then how can
I use your code as it overides the Edit method ?

Thx

Nov 21 '05 #9
Sam,

All is in the sample, so why not use that, just copy and paste you know.

Cor
Nov 21 '05 #10
Sam
yes that'd be great :)
but unfortunately I'd like to be able to do more complex things with my
datagrid. For instance a combobox field could receive records from a
table with the displaymember set to one of the field and the
valuemember set to the primary key. It seems to me that it's not
possible with this code, is it ?

Nov 21 '05 #11
Sam,

When you had set that in advance than I had tried it with that one.
DataGridComboboxStyle.

I did want to keep it simple for you and took the one I showed.

I think that now the chalenge is for you to see what I did with this one.

When you did not succeed in some days, maybe than I can try it with the
other one.

:-)

Cor
Nov 21 '05 #12
Sam
LOL :)
I don't have some days unfortunately, I have 1 day !
Anyway, I'm getting to it but it's f**ing hard for me...:(

Nov 21 '05 #13

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

Similar topics

0
by: chrisben | last post by:
Hi, I made a DataTable table and add four DataColumn to it. Then I created a DataView by calling dbv=new DataView (table). Then I insert some rows to the dataview and bind it to my datagrid as...
2
by: Fabrizio | last post by:
Hi, I created an aspx page with a Datagrid control that should list a bunch of records from a MS Access database table. When I load the page on Web Server , the datagrid itself is not visible....
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
4
by: Jussi | last post by:
I load a XML document in the DataGrid: private System.Windows.Forms.DataGrid myDataGrid = new DataGrid(); private DataSet m_myDataSet = new DataSet(); ...
13
by: Lyners | last post by:
I have a web page writen in ASP.NET that contains some javascript so that when a user presses a button, or edits a certain field in a datagrid, another cell in the datagrid is filled with a value....
0
by: Jennifer | last post by:
I had this beautiful datagrid on an ASP page (VB.Net as the code behind). When I clicked on a Select Button, the row was selected and the background color changed the way it was supposed to. The...
0
by: Guillaume | last post by:
Hi, I have an ArrayList filled with many Alarm object ( i will ad next this class definition). I use this arraylist as a datasource for my datagrid. I want to apply some table style, but it does...
0
by: Mani kansal | last post by:
hi, i have a problem with datagrid.Im using 2 dropdown lists in the datagrid.. and i want to fill one dropdown list on the selection of the item of the other one... like one grid is getting...
2
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi I'm on version 1.1. Not sure if this is possible. I've got a datagrid on a webpage with 3 columns, ID, Name and Email. The datagrid does not need to be connected to a datasource. I just...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.