|
Hi,
Use TableStyles and GridColumnStyles from the DataGrid properties. They work like a mask, you map the TableStyle to the entire collection and each GridColumnStyle to a column in your collection. Then you have two ways to hide the columns from a user: 1. Just don't create a GridColumnStyle for the columns you want to hide. or 2. Create GridColumnStyles for all you columns, and set the width of the columns you want to hide to 0 or 1 or something.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi Johan,
Thanks for your reply. I'm pretty new to VB.net so I apologise if I'm slow to catch on.
I am currently using the DataGridTableStyle and DataGridTextBoxColumm classes to modify the appearance of the datagrid but this doesn't seem to work. Is this the same as mapping to the TableStyle and GridStyleColumm classes you refer to?
My code is as follows:
Dim ts As DataGridTableStyle = New DataGridTableStyle
ts.MappingName = Clients.ActiveRecord.Branchs.MappingName
ts.AlternatingBackColor = System.Drawing.Color.LightBlue
Dim BranchIDColumn As New DataGridTextBoxColumn
BranchIDColumn.MappingName = "BranchID"
BranchIDColumn.HeaderText = "Branch ID"
BranchIDColumn.Width = 0
Dim BranchNameColumn As New DataGridTextBoxColumn
BranchNameColumn.MappingName = "Name"
BranchNameColumn.HeaderText = "Name"
BranchNameColumn.Width = 1000
Dim ClientIDColumn As New DataGridTextBoxColumn
ClientIDColumn.MappingName = "ClientID"
ClientIDColumn.HeaderText = "Client ID"
ClientIDColumn.Width = 0
Dim BranchDateColumn As New DataGridTextBoxColumn
BranchDateColumn.MappingName = "ModifiedDate"
BranchDateColumn.HeaderText = "Modified Date"
BranchDateColumn.Width = 0
' Adds the column styles to the grid table style.
ts.GridColumnStyles.Add(BranchIDColumn)
ts.GridColumnStyles.Add(BranchNameColumn)
ts.GridColumnStyles.Add(ClientIDColumn)
ts.GridColumnStyles.Add(BranchDateColumn)
' Add the table style to the collection, but clear the
' collection first.
Me.datBranchs.TableStyles.Clear()
Me.datBranchs.TableStyles.Add(ts)
' set datasource and hide columns
Me.datBranchs.SetDataBinding(Clients.ActiveRecord.Branchs.DataSource, "")
I have moved the SetDataBinding method to before I create the DataGridTableStyle and to the end where it currently is to see if that is the problem but all columns are visible even though I have set some to 0.
The mapping name is a string that is the class name of the objects stored in the collection ie. "clsBranch[]"
Thanks for any help you can provide.
David
|
|
|
|
|
Hi David,
As far as I can tell, you have build the TableStyle and everything correctly. However, because you create the TableStyle at runtime, you also need to link the TableStyle to the datagrid. By the look of things, that's all that is missing from your code.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks Johan. I will give that a go.
Kind regards
David
|
|
|
|
|
Hi Johan,
At the bottom of the code I add the table style to the tablestyles collection of the datagrid.
Me.datBranchs.TableStyles.Add(ts)
Is that what you mean by linking the tablestyle to the datagrid because it still doesn't work??? Maybe I should find another job!
Kind regards
David;)
|
|
|
|
|
Hi David,
No need to get another job, just do like me: lure a poor coder from India, Pakistan or Sri Lanka to where you live, with the empty promise of a greencard, have him do all the work, and claim it as your own.
But seriously...
You really did write it by the book, as far as I can tell, so I am not entirely sure why it still doesn't work. The only thing I can think of, for you to try is to use:
<br />
datBranchs.DataSource = WhatWasYourSourceDataSetAgain<br />
datBranchs.DataMember = "WhatTableInYouDataSetWasIt_IDontRemember"<br />
instead of .DataBinding at the end.
Regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I don't think I would be able to do that here in New Zealand (down by Australia if you don't know where that is) with our pc brigade, I would be hung, strung and quartered. No jokes about sheep please!
I will give that a go, thanks again Johan.
Regards
David
|
|
|
|
|
Hai everybody,
Am using Vb.net as my frond end and sql server 2000 as my back end.
in one of my screen am using grid control to view the data's in the tables, my problem is i want to filter the grid data's ie sno wise filter and name wise Filter. How can i do it? is it possible ? Please Give me detail description.
|
|
|
|
|
Do you want a filter from user input or filter the data before it gets to the page?
If you are wanting to pre-filter it then I would do that with your stored procedure.
If you are looking to do this based on user input then you can set you dataset/datatable = to a dataview. Then use a Dataview.Filter = "Column = Validated user input" which is similar to SQL but only requires the WHERE (which is what the "=" means) so remember to use ' ' for characters and the exact value for numerics.
Cleako
|
|
|
|
|
Thanks Mr.Cleako
I want to filter the data's by user input in text box and then he press a button. ie am filtering employee database in that database it contains more than 600 records inthat you want to extract particular employee from that database in that case only am in need of grid filter option. in my form i used 5 controls 3 buttons and a textbox and a grid, user given his input in a text box and then press any one button ie filterby empno or filterby ename or by department in that case am using below code for on of my button press but it was not working tell me some suggestion or code
Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click
con.Open()
str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'"
da = New OdbcDataAdapter(str, con)
da.Fill(Dspay, "empmaster1")
dgv.DataSource = Dspay
con.Close()
End Sub
Grid name is dgv
Dataset name is Dspay
table name is empmaster1
in pageload event am writing code for connection
Please help me.....
|
|
|
|
|
rrrriiizz wrote: Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click
con.Open()
str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'"
da = New OdbcDataAdapter(str, con)
da.Fill(Dspay, "empmaster1")
dgv.DataSource = Dspay
con.Close()
End Sub
If you are allowing them to type anything in the textbox then you should change your SQL to be "LIKE %'" & txtsearch.Text & "'%" instead. I would also suggest you not directly use the textbox text but set it to a variable and pre-validate what they typed because this can lead to a SQL Injection Attack by them typing in the correct commands.
Cleako
|
|
|
|
|
Mr.clicko
This command also not working Please help me
is my code is right? am n a great trouble with this filtering for past one week....
|
|
|
|
|
The "LIKE" does not work either? Have you tried typing something in that you know for sure is present?
Private Sub btneno_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneno.Click
con.Open()
str = "select * from empmaster1 where Eno='" & txtsearch.Text & "'"
da = New OdbcDataAdapter(str, con)
da.Fill(Dspay, "empmaster1")
dgv.DataSource = Dspay
con.Close()
End Sub One thing that I would suggest is to convert the Eno column to a varchar if it is currently a numeric column. I do not know if that is your DB setup or not but it's worth a try.
Select * FROM EmpMaster1 WHERE CAST(Eno AS VarChar(30)) LIKE %'" & txtSearch.Text & "'%"
Cleako
|
|
|
|
|
Mr.Cleako,
this is also not working cause am trying to get the values for Particular Employee name also. but it is also not working. thanks for your supports and help for past four days am not able to browse. thats what Late reply. if there is any other Method or technique is there for filtering please tell me and also code or syntax. Please Help.....
Thank You
|
|
|
|
|
First just try opening Query Analyzer and try something like this but replace "value" with something real.
Select * FROM EmpMaster1 WHERE EmployeeName LIKE '%value%' and if that works just translate it into something you can put into the code. Do the same for the number filter but you will probably need to do the cast to varchar in order for it to match if it is stored in the database as a number.
CleAkO
|
|
|
|
|
how to go through in data table data????????????????
Thiwa
|
|
|
|
|
foreach (DataRow row in table.Rows)
something like that
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi,
I have problem plssssssss give a solution of:
1. how can read Excel file using dialogbox?
2. How can get sql database n tables in to combobox or listbox
3. How can we refresh datagrid when we add new record in to database
c.p.desai
|
|
|
|
|
Why the bold font ?
chaiotali wrote: how can read Excel file using dialogbox?
you can't. A dialog box has nothing to do with it. You need to use the Office toolkit to talk to Excel, and it works the same, no matter what the UI.
chaiotali wrote: How can get sql database n tables in to combobox or listbox
You can do a select to get a list of the tables, then you can make that the datasource of your control
chaiotali wrote: How can we refresh datagrid when we add new record in to database
You can't, really, your database cannot send messages to your app.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I want to be able to insert at a particular place in a linked list. Im sure this is possible but how do u do it.
I can cycle through the linked list and find the position i want to insert but then how can i insert into this position.
Does anyone have any code examples.
Im using vb.net
|
|
|
|
|
What linked list are you using ? Isn't there an InsertAt method ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
This is actually a VB6 question. I'm trying to set up a VB DLL so that if it can't instantiate an external COM object because it is not registered properly it would run regsvr32.exe against the DLL to register the object and then try to instantiate it again. I'm using CreateProcess to run regsvr32 against the DLL and the problem I'm running into is that when the CreateProcess method is invoked, regsvr32 generates a dialog box indicating that LoadLibrary can't find the specified module. The module it prints out is the correct path to the DLL. Does anyone know how I can get this working?
|
|
|
|
|
I'm not sure, but it sounds like you're passing in a path to the .DLL that includes spaces. You'll have to enclose the path in double quote marks so the command line you pass to CreateProcess looks more like this:
REGSVR32 "C:\Program Files\Folder\Some Folder\MYDLL.DLL"
If not, RegSvr32 will look for a file called "Program" at the root of C:, not MYDLL.DLL in the path you want.
To build the path string with quote marks inside it, you have to use 2 quotes to get 1:
Dim path As String = """C:\Program Files\Folder...MYDLL.DLL"""
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am but I am enclosing the path in double-quotes. I found this out the first time I tried it without double-quotes. Regsvr32 complained about not being able to find the C:\Program component.
What I found was that I could set up an console app built in Visual C++ to do this and it worked fine if I ran it from the command line. But if I called the Visual C++ executable from my VB app, it gave me the same error. It looks like it has something to do with trying to run regsvr32.exe from a VB instantiated thread.
|
|
|
|
|
I never had a problem running RegSvr32 from VB6 or VB.NET. Since a process gets it's own seperate thread, regardless of which thread you create it from in your app, I don't see how this would cause a problem. Hmmm... Are you running multiple copies of RegSvr32 at the same time? (grasping at straws here...)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|