vb.net - Loop through DataGridView records and stop at the nearest match to my search criteria -


i have datagridview text values. user type text in textbox (txtsearch) , click button (btnsearch). want loop through values of column , stop @ first-match / closest match text in txtsearch.

example:

partnum         desc  pn10   pn10-1      pn10-13    pn12     pn12-1   pn12-2        pn12-3          pn13-1           pn15-2        pn19-1        

i want when user types pn12 in search textbox loop through ordered column , stop @ first match , if user searches not on list pn14-1 stop @ closest match "pn15-2"

i know how loop through rows , find exact match

for each row datagridviewrow in me.dgentries.rows      if row.cells.item("partnum").value = txtsearch.text         exit 

but how find closest match. have loop through search text letter letter??

trying define 'nearest' more rigorously might nearer answer. instance, if numeric, might 9996 'nearer' 9998 9990. once have clear idea of mean nearer can calculate distance each item in column. it's easy find nearest. ie use example 9998 gives distance of 2, while 9990 gives distance of 6.

edited in response comment:

i know it's strings, that's why said 'if were'. should able extrapolate answer strings well. need encode strings numbers in way captures idea of rank , place order - distance between aa , ad less distance between aa , da (cf 11 , 14 vs 11 , 41). instance, using base-26 ad 1 x 26 + 4 = 30. ca 3 x 26 + 1 = 79. distance between ad , ca therefore 49.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -