|
Is there a way to adjust the contents to a DataGridView to match what a user has typed in a textbox. As the user types in or removes a character from the text box, the DataGridView contents will adjust accordingly from the intial data populating the control from a Datatable. I would prefer to avoid loops, if at all possible. I would be willing to use a ListView control. I also tried to look for a method in a DataSet or DataTable and populate a second DataTable to bind to the grid, but could find a way. Any ideas?
Thank You
|
|
|
|
|
Not sure if I understand your question entirely, but you could try this:
Dim dt as New Datatable
'
'Code to fill your table
'
dim dv as new dataview(dt)
Datagrid1.datasource = dv
'Then in the Textbox TextChanged Event, you can modify the filter value
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
' "Name" is a column name in your datatable
dv.RowFilter = "Name LIKE ' " & Me.Textbox1.Text & " * ' "
'This will filter for anything that begins with whatever is typed in the textbox
End Sub
|
|
|
|
|
Thanks. Your code did exactly what I needed to do. I tweaked it somewhat. Here it is.
Private Sub txtSysName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSysName.TextChanged
'if nothing in textbox, display all rows
If Me.txtSysName.Text.Trim.Length = 0 Then
DataGridView1.DataSource = ds.Tables(0)
Msg.Text = "System count: " & DataGridView1.Rows.Count
Exit Sub
End If
'create dataview and populate with dataset populated in form load
Dim dv As New DataView(ds.Tables(0))
With dv
.Table = ds.Tables(0)
'.AllowDelete = True
'.AllowEdit = True
'.AllowNew = True
.RowFilter = "vchrName LIKE '" & Me.txtSysName.Text & "*'"
.RowStateFilter = DataViewRowState.CurrentRows
.Sort = "vchrName ASC"
End With
'reset grid datasource to contents of new dataview
DataGridView1.DataSource = dv
'display row count
Msg.Text = "System count: " & DataGridView1.Rows.Count
End Sub
|
|
|
|
|
Hey,
I'm a beginner in VB.NET and I'm trying to build a small application. In this application I create an object (user) on Form1 (IMSLogin). In my second form, I want to keep using the same object.
I tried to do this by coding the following:
IMSLogin is the form where the user-object is created.
<br />
Public Class IMSLogin<br />
Inherits System.Windows.Forms.Form<br />
Private frmMainMenu As MainMenu<br />
Public user As New User<br />
Me.frmMainMenu = New MainMenu(user)<br />
Me.frmMainMenu.Show()
MainMenu is the form where I want to use the user-object that was passed by via IMSLogin. This is my coding for MainMenu:
Public Class MainMenu<br />
Inherits System.Windows.Forms.Form<br />
<br />
Dim user As User<br />
<br />
Public Sub New(ByVal objUser As User)<br />
MyBase.New()<br />
<br />
'This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
<br />
Dim UserFromParent As User<br />
UserFromParent = objUser<br />
End Sub<br />
End Class
When I try to build my application, I get the following error:
"MainMenu" is a type in "WindowsApplication1" and cannot be used as an expression.
Can someone please help me with this? It's really urgent!
Thanks!!!!!!
G72360
|
|
|
|
|
I see 2 issues here...
1)
Me.frmMainMenu = New MainMenu(user)<br />
Me.frmMainMenu.Show()
The above code needs to be executed inside of a method. You should put it in the Form's load event handler, like this...
Private Sub IMSLogin_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.frmMainMenu = New MainMenu(user)
Me.frmMainMenu.Show()
End Sub
2)
In MainMenu's constructor, you didn't assign the objUser parameter to MainMenu's member variable. You assigned it to a local variable instead, which will be lost as soon as it goes out of scope in the constructor.
You should do this instead...
Private user As User
'
Public Sub New(ByVal objUser As User)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'
user = objUser
End Sub
I also have a couple nit-picky suggestions to make too.
1) You should avoid creating local/member variables having the same name as their type, like you did here.
Private user As User
Instead, call it something like "currentUser" or "loginUser" or whatever. It looks like you were doing a little hungarian notation here, so you could follow suit and call it "m_user" too.
2) You should post fix "Form" to the end of your Form class names. That makes it clear what they are and it'll follow Microsoft's naming guidelines. I think this is especially important for your MainMenu form class, which can easily be confused as a control.
|
|
|
|
|
I have a single datagrid, which is populated and repopulated by pressing a number of different buttons. The problem I have is that one of buttons when pressed will populate the datagrid with a column full of date information. But instead of 12/12/1999, it has 12/12/1999 00:00:00 as well for every row.
Here is my code, its pretty simple.
Private Sub btnFix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFix.Click
Dim Str = Session("TN")
Dim fix As New Fixtures()
DG.DataSource = fix.GetFixtures(Str)
DG.DataBind()
End Sub
I just want to know a quick and easy way to get rid of the 00:00:00 from the datagrid. And bare in mind that it's a shared datagrid and the other buttons don't put date info into it.
Cheers
|
|
|
|
|
Hi
Dont know what 'fix.GetFixtures(Str)' returns (Array, DataTable??), but why dont you format that data there using: Format(MyDate,"dd/MM/yyyy")
|
|
|
|
|
Posted this on the Visual C++ as well maybe I will find somebody that can help.
I have been looking for an answer on this one, but found only references to structures. Basically I have a VB.NET structure containing an member array of onother structure that has to be passed to unmanaged C++. I have been able to pass the structure which has members of type structure, but as soon as I define a member array of that structure I get an error: "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: The operation completed successfully."
This is how I am doing it:
VB.NET:
Public Structure SndStr2
<marshalas(unmanagedtype.i4)> Public memb1 As Integer
<marshalas(unmanagedtype.lpstr)> Public memb2 As String
<marshalas(unmanagedtype.i4)> Public memb3 As Integer
<marshalas(unmanagedtype.i4)> Public memb4 As Integer
End Structure
Public Structure SndStr1
<marshalas(unmanagedtype.i4)> Public memb1 As Integer
<marshalas(unmanagedtype.lpstr)> Public memb2 As String
<marshalas(unmanagedtype.i4)> Public memb3 As Integer
<marshalas(unmanagedtype.r8)> Public memb4 As Double
Public memb5() As SndStr2
End Structure
Declaration: Private Declare Function RcvFun Lib "...\RcvFun.dll" _
(ByRef SndVar As SndStr1) As String
Unmanaged C++:
struct RcvStr1 {
int memb1;
LPSTR memb2;
int memb3;
int memb4;
};
struct RcvStr2{
int memb1;
LPSTR memb2;
int memb3;
double memb4;
RcvStr1 *memb5;
};
LPSTR __declspec (dllexport) __stdcall RcvFun(RcvStr2 **RcvPtr)
{
RcvStr1 RcvVar1;
RcvVar1 = RcvPtr[0]->memb5[0];
return RcvVar1.memb2;
}
If there is anybody out there that did this before, please help!
|
|
|
|
|
I'm using VS.NET 2005 and am trying to consume a web service at the following URL:http://web-uat.datacraftsolutions.net/wsdl/receive2.wsdl[^]
I am able to add the web reference to my project, but do not have access to any on the methods that I am trying to use. The only classes that are made available are the HttpWebClientProtocol classes for each one of the methods I am looking to use.
My questions are as follows: Even though the vendor of this WSDL swears that it is properly constructed, is it? Secondly, can I do anything with the classes that have been exposed through the WSDL? Or am I going about this all the wrong way and there is a simpler approach to using their web service?
-- modified at 12:15 Wednesday 22nd February, 2006
|
|
|
|
|
Hello ,
Is there a way in vb.net that i can declare few variables and assign a
constant value to all of the variables at the same time?
Here is how i am trying ...
Dim x, y, p, q As Integer
x = y = p = q = 10
it doesn't throw any exception but when i debug these values variables
just have 0 but not 10.
How do i do this?
Tahnks-L
|
|
|
|
|
You can't really set them all with one line of code.
Dim x, y, p, q As Integer
x = 10
y = 10
p = 10
q = 10
"People who never make mistakes, never do anything."
My Blog
|
|
|
|
|
Yes thats what i thought that we can't assign all of them at once with the same value.
I was just curious was there a way to do it. How ever thanks for your time
Thanks
-L
|
|
|
|
|
No there is no way you could do so...
In fact the statement is interpreted as a = ( b = (c = 10 ) ) which is a set of boolean expressions: since c<>10 b would become 0 etc.
|
|
|
|
|
Hello ,
I am trying to manipulate the string
Dim str as string = "YS3EB45E833005745_20050610_WINDSHIELD"
Now i just need the part that is in between the two underscores. That is in the above string i just need that part 20050610.
I am trying to remember the function that i had used to identify the occurances of a particular character in the past.
Can any one help me with this?
Thanks
-L
|
|
|
|
|
you can use string.split() and it will be the second item in the returned array.
do you need to investigate an online backup[^] company
|
|
|
|
|
Could you please elobarate on how do we implement this in my case?
Thanks
-L
|
|
|
|
|
|
Yes this works here is what i did off course the same
Dim MyString As String = "YS3EB45E833005745_20050610_WINDSHIELD"
MySplitLine = MyString.Split("_")
MessageBox.Show(MySplitLine(1))
and its returning 20050610
But like you mentioned .ToCharArray()may be an efficient way of doing it.
we need to use ToCharArray() because we are splitting a string?
Thanks
-L
|
|
|
|
|
Slow Learner wrote: we need to use ToCharArray() because we are splitting a string?
No, I use it for documentation purposes, it is more clear what the code is doing, imo, when I see tochararray(). That being said, I recall I may have had issues when I had a string longer than one charater. Nonetheless, your code returns the correct results, so at the end of the day, our code is managerially equvilant
Slow Learner wrote: .ToCharArray()may be an efficient way of doing it.
Although many people will argue this point to death, I feel efficent is only releveant in the 20% of the code that does 80% of the work in the program. Most of a program is scaffolding to support the core logic, anyway. Therefore, who cares if some ui element take 20 extra ns to complete. The user cant tell the difference! 80% of the code should be simple and readable 20% (that which does the work) should be "efficent"
do you need to investigate an online backup[^] company
|
|
|
|
|
Sure i like your arugment. If the code is more readable and understandable it would be easy for another developer who comes in after we left. I agree with you
thanks
-L
|
|
|
|
|
If you would like the code to be more efficient, you should get rid of the Split all together (as that creates at least two strings that you don't even use). Use IndexOf to locate the first and second "_" in the string, then use Substring to get the part of the string in between.
Still I agree with Jason's opinion that most of the code doesn't need to be optimized to the max. Consider how often the code will be used, and how much resources it uses compared to the surronding code.
Simple code that works is always better than optimized code that doesn't.
---
b { font-weight: normal; }
|
|
|
|
|
Good explanation and thanks for the reply. I am excited trying the same thing in different ways and figure out the best option.
Here is how i am trying to get the index of the string i posted in my string YS3EB45E833005745_20050610_WINDSHIELD
Dim indexOf_ As Integer
indexOf_ = fileName.IndexOf("_")
the above one gives me the index of the first occurance of the "_". How do i get the second occurance of the "_" and then use the substring?
Thanks for the reply,
-L
|
|
|
|
|
You can use either LastIndexOf("_") or IndexOf("_", indexOf_ + 1).
For Substring you need the index of the first character and the length.
The first character is located at indexOf_ + 1.
The length I believe is the index of the second _ minus indexOf_ minus one.
---
b { font-weight: normal; }
|
|
|
|
|
I want to connect sql with vb.net and want to add and delete the record programically i.e using insert alter command etc. If somebody helps me , I am in urgent need of it.
Thanks and Regards
Pankaj Garg
|
|
|
|
|