By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,010 Members | 2,774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,010 IT Pros & Developers. It's quick & easy.

easy grid editing ? ? ? (equivalent to msflexgrid)

P: n/a
can someone explain how to simply populate a grid in .net ? the way i
understand it, there is no more msflexgrid, and instead is this new
control that has to be tied to a dataset, and it is a real pain to
work with if you just want to throw some values in a grid and edit
them with a textbox. i don't want to persist anything in a database, i
just need a fast cheap and easy grid in memory that i can work with!

i had functions in vb6 that would insert (tab & vbcrlf) delimited text
into a grid, and vice versa. it was super easy. if you clicked on the
grid, it would superimpose a textbox you could type in, and on lost
focus, the textbox contents got copied into the appropriate cell.

is there some existing code to do this in vb.net easily?
(i stress EASILY! it's 2004, this kinda stuff is supposed to get
easier as technology advances is it not!)

many thanks

-----

vb6 code i want to find equivalent to:

'this function converts tab/vbcrlf delim text to a msflexgrid
Function fn_sCopyGridToText(ByRef grdTemp As Object, ByVal iFirstRow
As Integer, ByVal iFirstCol As Integer) As String

'this function converts contents of msflexgrid to delim (eg
tab/vbcrlf) text
Sub subCopyTextToGrid(ByRef sString As String, ByRef grdTemp As
Object, ByVal iFirstRow As Integer, ByVal iFirstCol As Integer, ByVal
sRowDelim As String, ByVal sColDelim As String, ByVal bClearGrid As
Boolean)

'when user clicks msflexgrid, puts a textbox over the cell they
clicked on so they can edit text in cell
Private Sub grdValues_Click()
Dim sGridDisplay As String

' SAVE POSITION
g_dictValues.Item("iGridRow") = grdValues.Row
g_dictValues.Item("iGridCol") = grdValues.Col

' GET VALUE
sGridDisplay = fn_No_Empty(grdValues.TextMatrix(grdValues.Row,
grdValues.Col), "", True) ' get value in grid

' BUILD TEXT BOX, PLACE OVER CURRENT CELL
txtEdit.Text = sGridDisplay ' copy text of current cell into edit
box
txtEdit.Top = grdValues.Top + grdValues.CellTop
txtEdit.Left = grdValues.Left + grdValues.CellLeft
txtEdit.Width = grdValues.CellWidth
txtEdit.Height = grdValues.CellHeight
txtEdit.Text = grdValues.Text
g_dictValues.Item("sOriginalText") = grdValues.Text
txtEdit.Visible = True
txtEdit.SetFocus

End Sub ' grdValues_Click

'when user exits textbox, save contents in grid
Private Sub txtEdit_LostFocus()

' ================================================== =================
' SAVE TEXT IN GRID
grdValues.TextMatrix(g_dictValues.Item("iGridRow") ,
g_dictValues.Item("iGridCol")) = txtEdit.Text
'grdValues.TextMatrix(g_iGridRow, g_iGridCol)
txtEdit.Visible = False

End Sub ' txtEdit_LostFocus
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Mad,

The answer on your question is very simple.

The only thing you have to know is that using a datagrid is as well using a
table where the datatable is the most easy one for that.

To show you how easy I type it in here beneath without checking so watch
typos, I assume you have pulled a datagrid1 on your form

I hope this helps?

Cor

\\\
dim dt as new datatable
dt.columns.add("Mad")
dt.columns.add("Cor")
for i as integer = 0 to 9
dim dr as datarow = dt.newrow
dr(i)(0)= i.tostring
dr(i)(1)= chr(i + 64)
dt.rows.add(dr)
next
datagrid1.datasource = dt
///
can someone explain how to simply populate a grid in .net ? the way i
understand it, there is no more msflexgrid, and instead is this new
control that has to be tied to a dataset, and it is a real pain to
work with if you just want to throw some values in a grid and edit
them with a textbox. i don't want to persist anything in a database, i
just need a fast cheap and easy grid in memory that i can work with!

i had functions in vb6 that would insert (tab & vbcrlf) delimited text
into a grid, and vice versa. it was super easy. if you clicked on the
grid, it would superimpose a textbox you could type in, and on lost
focus, the textbox contents got copied into the appropriate cell.

is there some existing code to do this in vb.net easily?
(i stress EASILY! it's 2004, this kinda stuff is supposed to get
easier as technology advances is it not!)

many thanks

-----

vb6 code i want to find equivalent to:

'this function converts tab/vbcrlf delim text to a msflexgrid
Function fn_sCopyGridToText(ByRef grdTemp As Object, ByVal iFirstRow
As Integer, ByVal iFirstCol As Integer) As String

'this function converts contents of msflexgrid to delim (eg
tab/vbcrlf) text
Sub subCopyTextToGrid(ByRef sString As String, ByRef grdTemp As
Object, ByVal iFirstRow As Integer, ByVal iFirstCol As Integer, ByVal
sRowDelim As String, ByVal sColDelim As String, ByVal bClearGrid As
Boolean)

'when user clicks msflexgrid, puts a textbox over the cell they
clicked on so they can edit text in cell
Private Sub grdValues_Click()
Dim sGridDisplay As String

' SAVE POSITION
g_dictValues.Item("iGridRow") = grdValues.Row
g_dictValues.Item("iGridCol") = grdValues.Col

' GET VALUE
sGridDisplay = fn_No_Empty(grdValues.TextMatrix(grdValues.Row,
grdValues.Col), "", True) ' get value in grid

' BUILD TEXT BOX, PLACE OVER CURRENT CELL
txtEdit.Text = sGridDisplay ' copy text of current cell into edit
box
txtEdit.Top = grdValues.Top + grdValues.CellTop
txtEdit.Left = grdValues.Left + grdValues.CellLeft
txtEdit.Width = grdValues.CellWidth
txtEdit.Height = grdValues.CellHeight
txtEdit.Text = grdValues.Text
g_dictValues.Item("sOriginalText") = grdValues.Text
txtEdit.Visible = True
txtEdit.SetFocus

End Sub ' grdValues_Click

'when user exits textbox, save contents in grid
Private Sub txtEdit_LostFocus()

' ================================================== =================
' SAVE TEXT IN GRID
grdValues.TextMatrix(g_dictValues.Item("iGridRow") ,
g_dictValues.Item("iGridCol")) = txtEdit.Text
'grdValues.TextMatrix(g_iGridRow, g_iGridCol)
txtEdit.Visible = False

End Sub ' txtEdit_LostFocus

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.