Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Converting a Datarow() to a Datatable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Komandur Kannan - 19 Sep 2007 09:26 GMT
Hi
   Is it possible to convert a Datarow() to a Datatable in more simpler way.

Parameswaran.N
PvdG42 - 19 Sep 2007 13:05 GMT
> Hi
>    Is it possible to convert a Datarow() to a Datatable in more simpler
> way.
>
> Parameswaran.N

OK, simpler than what?
How can anybody here offer you "simpler" suggestions if we don't know what
you are doing now?
Walter Wang [MSFT] - 20 Sep 2007 06:47 GMT
Hi Parameswaran,

Would you please tell us more about your existing implementation and
objective here? Thanks.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Komandur Kannan - 20 Sep 2007 08:16 GMT
Hi Wang,

Thanks for the reply

Objective:
      I am having  a combobox which has a multicolumn. The Data is got from
the Oracle database which I have bound the data to the multicolumn
combobox(Usercontrol). Now for every on every keypress of the user the data
has to get sorted out and has to get listed. User will select the data and
will process the next level.

Example:
ProductMaster
ProductCode|ProductName
this will be bounded to the combobox

If the User types the ProductCode(numeric) the search will be made on Code,
Else on the Name(Alpha),  

My Plan was to search from the datatable
          Using datatable.select("productcode like '%" & " %'") for this
the return is only datarows for me. Where I cannot bind the datarows to the
combox..

I am now creating a temprary table coyping the datarows using the looping
and re-binging it to the Combobox.

That is the reason I was asking for a easy way to convert a datarow() to a
datatable.

Regards,
Parameswaran.N





> Hi Parameswaran,
>
[quoted text clipped - 11 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 21 Sep 2007 05:52 GMT
Hi Parameswaran,

How about using DataTable.DefaultView.RowFilter to filter the data?

           dt.DefaultView.RowFilter = "Code like '1%'";
           comboBox1.DataSource = dt;
           comboBox1.DisplayMember = "Name";

This way you don't need to convert the selected DataRow to another
DataTable.

Please let me know if there's anything unclear. Thanks.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Komandur Kannan - 22 Sep 2007 08:30 GMT
Hi Wang
      Thanks for your reply
       I have some problem. I was trying the above in key press event. But
its not working fine When I do this It clears the combobox text.

       I can send you the code. where you can check and get back to me.

Regards,
Parameswaran.N

> Hi Parameswaran,
>
[quoted text clipped - 19 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 24 Sep 2007 02:48 GMT
Hi Parameswaran,

No problem, please feel free to send me your code. Preferrably a small but
complete project that could reproduce the issue easily. Thanks for your
effort. You can find my email in my signature.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 25 Sep 2007 06:08 GMT
Hi Parameswaran,

Thanks for your code. I've debugged your code and found the cause.

In your KeyUp() code:

 MultiColumnCombo1.DroppedDown = True
 orads.DefaultView.RowFilter = "prod_desc like '%" &
MultiColumnCombo1.Text & "%'"

If you add following code before setting the RowFilter:

 Me.Text = MultiColumnCombo1.Text

You will see the Text is not the text you just entered, but some item in
the list.

Now if you move the "Me.Text = ..." line before
"MultiColumnCombo1.DroppedWon = True", you will see the displayed text in
Form's title is correct. This is because when you drop down a ComboBox, the
text in its edit area will get replaced with the first item in the list.

Therefore to fix this issue, set DroppedDown=True after setting RowFilter.

Hope this helps.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Komandur Kannan - 25 Sep 2007 12:08 GMT
Hi Wang
      Thanks for the reply

I sorry if I had misunderstood you

Me.Text = MultiColumnCombo1.Text
           orads.DefaultView.RowFilter = "prod_desc like '%" &
MultiColumnCombo1.Text & "%'"
           MultiColumnCombo1.DroppedDown = True

Is this the way u had asked me to put

Wang there is another problem.. If I select any data from the dropdown

Error It says
"There is no row at position 1."

Please advice me

regards
Parameswaran.N

> Hi Parameswaran,
>
[quoted text clipped - 32 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 28 Sep 2007 08:24 GMT
Hi Parameswaran,

I have spent about two hours researching on your problem. I found that the
exception is caused in the following situation:

1. At first, I type a char in the derived combobox and the drop down list
appears with some items in it.
2. I type some other chars in the derived combobox and there's no data
matching the text in the combobox so there's no item in the drop down list
now (but the drop down list is still opened at this time).
3. Click somewhere else on the form. The drop down list is to be closed and
an exception occurs "InvalidArgument=Value of '0' is not valid for
'index'.".

That is, if there're items in the drop down list when the drop down list is
opened, but these items are all removed before the drop down list is
closed, an exception would occur when the drop down list is to be closed. I
think this exception is caused by the internal implementation of ComboBox.
After all, changing the items in the drop down list when the drop down list
is opened is not a common usage.

To avoid this problem, I suggest that you don't show the drop down list
when the user typies into the derived combobox, but show the drop down list
when the user presses the Enter key after the input finishes. When the drop
down list is opened, the user could select an item from the drop down list.

The following is a sample.

Public Class Form1

   Dim orads As New DataTable
   Dim binding As New BindingSource

   Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
   
       AddHandler MultiColumnCombo1.TextChanged, AddressOf
MultiColumnCombo1_TextChanged
       AddHandler MultiColumnCombo1.KeyDown, AddressOf
MultiColumnCombo1_KeyDown

       Dim col As New DataColumn("PROD_CODE", GetType(Integer))
       orads.Columns.Add(col)
       col = New DataColumn("PROD_DESC", GetType(String))
       orads.Columns.Add(col)

       Dim row As DataRow = orads.NewRow()
       row(0) = 1
       row(1) = "a"
       orads.Rows.Add(row)
       row = orads.NewRow()
       row(0) = 2
       row(1) = "b"
       orads.Rows.Add(row)
       row = orads.NewRow()
       row(0) = 3
       row(1) = "aa"
       orads.Rows.Add(row)
       row = orads.NewRow()
       row(0) = 4
       row(1) = "bb"
       orads.Rows.Add(row)

       binding.DataSource = orads

       Me.MultiColumnCombo1.DataSource = binding
       Me.MultiColumnCombo1.DisplayMember = "PROD_DESC"
       Me.MultiColumnCombo1.ValueMember = "PROD_CODE"
       Me.MultiColumnCombo1.ColumnWidths = "250;80"

   End Sub

   Private Sub MultiColumnCombo1_TextChanged(ByVal sender As Object, ByVal
e As System.EventArgs)

       Me.MultiColumnCombo1.DroppedDown = False
       If (Me.MultiColumnCombo1.Text = "") Then
           Me.binding.Filter = ""
           Me.MultiColumnCombo1.SelectedIndex = -1
       Else
           RemoveHandler MultiColumnCombo1.TextChanged, AddressOf
MultiColumnCombo1_TextChanged
           Dim currenttext As String = Me.MultiColumnCombo1.Text
           Me.binding.Filter = "prod_desc like '%" &
Me.MultiColumnCombo1.Text & "%'"
           Me.MultiColumnCombo1.Text = currenttext
           SendKeys.Send("{END}")
           AddHandler MultiColumnCombo1.TextChanged, AddressOf
MultiColumnCombo1_TextChanged

       End If

   End Sub

   Private Sub MultiColumnCombo1_KeyDown(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyEventArgs)
       If (e.KeyCode = Keys.Enter) Then
           Me.MultiColumnCombo1.DroppedDown = True
           e.Handled = True
       End If
   End Sub
End Class

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
Komandur Kannan - 30 Sep 2007 09:07 GMT
Hi Liu,
       Thanks alot for the effort you had put for me...

Liu My requirement is some thing when the user types the dropdown has to get
rearraged accordingly

Say If the User types "B" the combobox has to rearrage and list me all the
Item in "B" again if the user types "BE" then accordingly the list item has
to be made for "BE" and list to the user. Now the user will select from the
list in the combobox.

User will press "ENTER" to select from the list and move to the next control.

Please advice me if I am working correctly for the above problem... If so
please advice me the correct way to approach

Regards,
Parameswaran.N

> Hi Parameswaran,
>
[quoted text clipped - 105 lines]
> Linda Liu
> Microsoft Online Community Support
Jeffrey Tan[MSFT] - 02 Oct 2007 07:23 GMT
Hi Parameswaran,

Sorry for letting you wait.

We will some some time to perform research on this issue and get back to
you ASAP. Thanks for your patient.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 04 Oct 2007 11:23 GMT
Hi Parameswaran,

Thank you for your reply!

As I have mentioned in my previous reply, the exception is caused in this
case: there're items in the drop down list when the drop down list is
opened, but these items are all removed before the drop down list is closed.

It seems that there's no method to solve the above problem. But we could
avoid this problem by not showing the drop down list when the user typies
into the ComboBox. We could then show the drop down list when the user
finishes input and presses the Enter key in the ComboBox.

It isn't too much different from what you expect.

Please try the sample code I provided in my previous reply to see if
there're problems.

Sincerely,
Linda Liu
Microsoft Online Community Support
Komandur Kannan - 04 Oct 2007 13:54 GMT
Hi Liu,
      Thanks for you reply!

We can close this thread.

Thanks for the support you had given us.

Regards
Parameswaran.N


> Hi Parameswaran,
>
[quoted text clipped - 17 lines]
> Linda Liu
> Microsoft Online Community Support

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.