Hi All,
I have a datagrid that reads from a data source with no problem. The problem is, after loading the data in the datagrid i have the last row empty by default ( the one with the asterics beside it ). this grid have aother child grid, so, when i navigate between the rows of the main grid the related data in the child grid changes according to the current selected row. So when ever i go to the empty row an error occurs. Simply i have to hide this empty row ( by the way, this row is used for new enteries ) and this can be done by changing the read only property of the main grid to True, the problem is i need to update the data in the main grid as well, and the read only mode prevents that.
Another question, is it possible to add a control in the grid itself. e.g. can i have a drop down menu shown inside the grid once i click inside a cell in a specific field. - I am using a data grid in WINDOWS FORMS application.
thanks a lot in advance.
4 5188
Hi All,
I have a datagrid that reads from a data source with no problem. The problem is, after loading the data in the datagrid i have the last row empty by default ( the one with the asterics beside it ). this grid have aother child grid, so, when i navigate between the rows of the main grid the related data in the child grid changes according to the current selected row. So when ever i go to the empty row an error occurs. Simply i have to hide this empty row ( by the way, this row is used for new enteries ) and this can be done by changing the read only property of the main grid to True, the problem is i need to update the data in the main grid as well, and the read only mode prevents that.
Another question, is it possible to add a control in the grid itself. e.g. can i have a drop down menu shown inside the grid once i click inside a cell in a specific field. - I am using a data grid in WINDOWS FORMS application.
thanks a lot in advance.
Would you be able to post your code, AYasser?
I think you will get more hits this way, helps experts see what you're stuggling with straigh away and offer advice.
Let us know...
Welcome!
It might be just the setting of .AllowAddNew which is causing the extra line. I believe the asterisk indicates it's a new entry, like you see at the bottom of the table/query grid when you work directly in MS Access
EDIT: Just had a look in the help. Here's what I found... Remarks
If the AllowAddnew property is True, the last row displayed in the DataGrid control is left blank to permit users to enter new records. If the AllowAddNew property is False, no blank line is displayed.
.
Thanks a lot gents. i have had the problem solved yesterday by setting the data bindings of the datagrid to a dataview.
The AllowNew command is not accessible except through a dataview as i understood. but anyway it works fine right now thanks for your immediate reply.
The other question is still valid. Can i have a control embeded in a windows form datagrid.? e.g. can i have a dropdown list in a cell in a datagrid? so whenever i click a cell in a specific column in the grid it transforms to a dropdown list from which i can choose something , and my choice become the new cell value?
"The other question is still valid. Can i have a control embeded in a windows form datagrid.? e.g. can i have a dropdown list in a cell in a datagrid? so whenever i click a cell in a specific column in the grid it transforms to a dropdown list from which i can choose something , and my choice become the new cell value?"
Yes you can!!
The DataGrid, just like a form has a Controls Collection, that can be added to.
In this bit of code I removed the text box controls for a specified column (as otherwise they appear over the top of the control I have added to the datagrid)
I have then added a button and comboBox with event handlers to a DataGrid called dgrUserDetails. These controls were declared at the top of the page like this: - Dim ThisTexBox As New TextBox
-
Dim ThisButton As New Button
- 'This stops the textbox from appearing over the top
-
dgrUserDetails.Controls.RemoveAt(10)
-
dgrUserDetails.Controls.RemoveAt(9)
-
-
'This Creates the ComboBox
-
ThisComboBox.Items.Add("Read")
-
ThisComboBox.Items.Add("Full")
-
ThisComboBox.Items.Add("Admin")
-
-
'And add it to the Datagrid's Controls collection
-
dgrUserDetails.Controls.Add(ThisComboBox)
-
ThisComboBox.Visible = False
-
'This gives it an event
-
AddHandler ThisComboBox.SelectedValueChanged, AddressOf OnComboBoxValueSelect
-
-
dgrUserDetails.Controls.Add(ThisButton)
-
ThisButton.Visible = False
-
ThisButton.Text = "Change"
-
-
ThisButton.Font = New Font(ThisButton.Font.FontFamily, 7, FontStyle.Regular, GraphicsUnit.Point)
-
AddHandler ThisButton.Click, AddressOf OnButtonClick
The other thing I think you would want to do is control where the control appears. This bit of code make the control appear over the cell you have clicked: - Private Sub dgrUserDetails_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgrUserDetails.CurrentCellChanged
-
'This prevents them from being visible if focus changes
-
ThisComboBox.Visible = False
-
ThisButton.Visible = False
-
Dim ThisControl As Control
-
-
'This works out the Column selected
-
If dgrUserDetails.CurrentCell.ColumnNumber = 9 Then
-
'This makes it visble
-
ThisComboBox.Visible = True
-
-
'It sets it's position to be the same as the Current Cell
-
ThisComboBox.Location = New Point(dgrUserDetails.GetCurrentCellBounds.X, dgrUserDetails.GetCurrentCellBounds.Y)
-
ThisComboBox.Height = dgrUserDetails.GetCurrentCellBounds.Height
-
ThisComboBox.Width = dgrUserDetails.GetCurrentCellBounds.Width
-
ElseIf dgrUserDetails.CurrentCell.ColumnNumber = 8 Then
-
ThisButton.Visible = True
-
ThisButton.Location = New Point(dgrUserDetails.GetCurrentCellBounds.X, dgrUserDetails.GetCurrentCellBounds.Y)
-
ThisButton.Height = dgrUserDetails.GetCurrentCellBounds.Height
-
ThisButton.Width = dgrUserDetails.GetCurrentCellBounds.Width
-
End If
-
End Sub
Finally you would want it to update the right cell!! This one is for the ComboBox - Private Sub OnComboBoxValueSelect(ByVal sender As Object, ByVal e As System.EventArgs)
-
Dim ThisComboBox As ComboBox = CType(sender, ComboBox)
-
'This now makes the cell's value match that of the combo box
-
dgrUserDetails.Item(dgrUserDetails.CurrentCell.RowNumber, dgrUserDetails.CurrentCell.ColumnNumber) = ThisComboBox.SelectedItem
-
ThisComboBox.Visible = False
-
End Sub
I hope this makes some sort of sense.
Best Wishes G.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: vincent |
last post by:
Hello,
How do i get the last row OnItemDataBound in Datagrid or
atleast the number of rows OnItemDataBound in Datagrid?
thanks
Vincent
|
by: Ryan Liu |
last post by:
Hi,
when I edit a cell in datagrid, I need click on another cell to save the
current cell. But when I close the form, the last modified cell is not
changed, how can I prevent this?
Thanks a...
|
by: Ryan Liu |
last post by:
Hi there,
I got a NullReferenceException when delete last row in a datagrid.
I had hard time to solve since it does not occur in my own code.
I put a datagrid in my inherited user control,...
|
by: Peter Afonin |
last post by:
Hello:
When I print the report based on the datagrid content, often the last line
on the page is cut in half, and the next half appears on the next page. How
can I format the page to avoid this?...
|
by: Hajime Kusakabe |
last post by:
I made a datagrid and it contains several columns.
The number of columns depend on what users select from a dropdown list.
Therefore the number of columns changes.
I would like to find the last...
|
by: Diego F. |
last post by:
I'm trying to print a DataGrid. I use javascript and can print it but the
last line gets cut, as well as I don't have the control horizontally.
How do you print a DataGrid?
--
Regards,
...
|
by: tupolev |
last post by:
Hello
Is there a way to find the last row in the datagrid BEFORE I save the
changes to the table?
Tupolev
|
by: beachboy |
last post by:
any most fast method that we can know the idicate the first row and last row
in datagrid?
..NET 1.1
Thanks in advanced.
|
by: =?Utf-8?B?UGhpbCBKb2huc29u?= |
last post by:
I have data that spans over several pages in a datagrid.
On the last page, the row heights seem to justify vertically, so if there
are say 14 records and the paging is ten, each row on the last...
|
by: marlberg |
last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc
Language: C#, ASP.NET
Pre-compiled Libraries: Enterprise Library 3.0 full
I have a requirement to implement in and display in C# and...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
| |